#include <stdio.h>
#define MAX_SIZE 20
int main()
{
int age;
char name[MAX_SIZE];
float wage;
printf("input name, age and wage: ");
scanf("%s %s %s", name, &age, &wage); //LINE 10
}
after trying to compile:
lab4q5.c: In function 'main':
lab4q5.c:10: warning: format '%s' expects type 'char *', but argument 3 has type 'int*'
lab4q5.c:10: warning: format '%s' expects type 'char *', but argument 4 has type 'float *'
lab4q5.c:16: warning: control reaches end of non-void function
Im new to C programming and want to scan a float
and int
but as a String for one of my labs. I know i can change the %s %s
to %f %d
and it should compile fine, but I'm being asked to scan if as a %s
, any help would be much appreciated:
the part of the question I'm having trouble with is below:
use loop to read inputs (from standard in), one input per line, about the user information in the form of name age wage, where age is an integer literal, and wage is a floating point literal with up to 2 decimal number. • use scanf(“%s %s %s”, name, age, wage) to read in three input ‘strings’;
so after reading the comments ive decided to format them as strings and then worry about manipulating them as int and float later, this is what I have so far:
#include <stdio.h>
#define MAX_SIZE 20
#define MAX_AGE 3
int isXX(char name[])
{
if (name[0] == 'X' && name[1] == 'X' && name[2] == '\0')
return 0; //return return false to quit
else
return 1; //return true
}
int main()
{
char age[MAX_AGE];
char wage[MAX_SIZE];
char name[MAX_SIZE];
printf("input name, age and wage: ");//enter name as XX to quit
scanf("%s %s %s", name, age, wage);
while(isXX(name[])) // //LINE 22
{
printf("input name, age and wage: ");//enter name as XX to quit
scanf("%s %s %s", name, age, wage);
}
return 0;
}
now im not sure why im getting this error in compiler but i am
lab4q5.c: In function âmainâ:
lab4q5.c:22: error: expected expression before â]â token