-1

I keep getting a read access violation whenever I try to run this code:

#include<stdio.h>
#include<stdlib.h>

int i = 0;
struct basicValues{
    float rate, hoursWorked, grossPay, basePay, overtimePay, taxesPaid, netPay;
    char name[15];
};

void inputValues (struct basicValues *entered)
{   
    printf("Please enter your name, hourly pay, and hours worked this week: ");
    scanf_s("%s %f %f", entered->name, entered->rate, entered->hoursWorked);

}



void main()
{
    int i = 0;
    struct basicValues workers[5];

    for (i = 0; i < 5; ++i)
    {
        inputValues(&workers[i]);
        printf("%c %f %f", workers[i].name, workers[i].rate, workers[i].hoursWorked);
        system("pause");
    }

}

I think it has to do with my structure inputValues but I don't know what to change. Thanks

  • 1
    Perhaps you should [find a good beginners book or two](http://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list), because you're not passing the correct arguments to `scanf`. – Some programmer dude Jul 16 '17 at 17:50
  • `scanf_s("%s %f %f", entered->name, entered->rate, entered->hoursWorked);` --> `scanf_s("%s %f %f", entered->name, sizeof(entered->name), &entered->rate, &entered->hoursWorked);`, `printf("%c %f %f", workers[i].name, workers[i].rate, workers[i].hoursWorked);` --> `printf("%s %f %f", workers[i].name, workers[i].rate, workers[i].hoursWorked);` – BLUEPIXY Jul 16 '17 at 19:35
  • `scanf_s("%s"...` requires 2 following arguments. – chux - Reinstate Monica Jul 16 '17 at 20:18

1 Answers1

0

You should add & before primitive value types, as scanf expects the address of the variables. Like this

&entered->rate,   &entered->hoursWorked

Also use %s, not %c when printing a string

kkica
  • 4,034
  • 1
  • 20
  • 40