1

I do not understand why I am receiving this exception every time I attempt to enter a value for name.

This is the exception I get, Exception thrown at 0x0F59B211 (ucrtbased.dll) in Program3.exe: 0xC0000005: Access violation writing location 0xFFFFFFCC.

If there is a handler for this exception, the program may be safely continued.

I am new to c so please explain thoroughly.

#include <stdio.h>
#include <string.h>

int askUser(char name[5][16],float hourlyRate[5],float hoursWorked[5])
{
    int counter = 0;

for (int i = 0; i < 5; i++)
{

    printf("enter name: ");
    scanf_s("%15s", name[i], 16);
    if (strcmp(name[i], "-1") == 0)
        break; 
    printf("enter hourly rate: ");
    scanf_s("%f", &hourlyRate[i]);
    if (hourlyRate[i] == -1)
        break;
    printf("enter hours worked: ");
    scanf_s("%f", &hoursWorked[i]);
    if (hoursWorked[i] == -1)
        break;

    counter++;
}

return counter;
}

void main()
{
const float OVERTIMEHOURS = 40.0f;
const float OVERTIMERATE = 1.5f;
const float TAX = 0.20f;
char name[5][16] = { "", "", "", "", "" };
float hourlyRate[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float hoursWorked[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float amountPaid[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float basePay[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float overPay[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float taxPaid[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float netPay[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float overTime[5] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float totalPaid = 0.0f;

int counter = 0;


counter = askUser(name[5][16], &hourlyRate[5], &hoursWorked[5]);
}
2
  • 1
    Please provide a minimal example that reproduce your bug Commented Jul 23, 2016 at 7:50
  • At this stage in your programming career, you should assume that if the compiler generates a warning, you've got a bug in your code. Even a few years down the road, that'll still be the case far more often than not (99 times out of 100). Commented Jul 23, 2016 at 12:15

1 Answer 1

1

You are going wrong here

counter = askUser(name[5][16], &hourlyRate[5], &hoursWorked[5]);

Your function askuser require first argument of type char[][] but you are passing argument of type char and this goes true for all the passed arguments

so the corrected call to askuser() should be

counter = askUser(name, hourlyRate, hoursWorked);

The same error is repeated twice more in main Please take a look at compiler warnings before running the code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.