I am using CodeBlocks and learning C. I created this simple script as a point for learning functions. I am not understanding the error I am getting though as everything matches up in my eyes.
CODE:
#include <stdio.h>
#include <string.h>
void SetPerson(char a, int b);
int main () {
char name[50];
int number[6];
printf("Enter Name: ");
scanf("%49s", name);
printf("Enter Number: ");
scanf("%5d", number);
SetPerson(name, number);
return(0);
}
void SetPerson(char a, int b) {
printf("Name: %s\n", a);
printf("Number: %d", b);
}
In the compiler I am getting these errors:
||=== Build: Debug in remove (compiler: GNU GCC Compiler) ===|
C:\Users\e\Desktop\c programs\remove\main.c||In function 'main':|
C:\Users\e\Desktop\c programs\remove\main.c|17|warning: passing argument 1 of 'SetPerson' makes integer from pointer without a cast [-Wint-conversion]|
C:\Users\e\Desktop\c programs\remove\main.c|4|note: expected 'char' but argument is of type 'char *'|
C:\Users\e\Desktop\c programs\remove\main.c|17|warning: passing argument 2 of 'SetPerson' makes integer from pointer without a cast [-Wint-conversion]|
C:\Users\e\Desktop\c programs\remove\main.c|4|note: expected 'int' but argument is of type 'int *'|
C:\Users\e\Desktop\c programs\remove\main.c||In function 'SetPerson':|
C:\Users\e\Desktop\c programs\remove\main.c|23|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]|
||=== Build finished: 0 error(s), 3 warning(s) (0 minute(s), 0 second(s)) ===|
EDIT:
I changed as recommend:
SetPerson(char *a, int b);
And now I am at these errors:
||=== Build: Debug in remove (compiler: GNU GCC Compiler) ===|
C:\Users\e\Desktop\c programs\remove\main.c||In function 'main':|
C:\Users\e\Desktop\c programs\remove\main.c|17|warning: passing argument 2 of 'SetPerson' makes integer from pointer without a cast [-Wint-conversion]|
C:\Users\e\Desktop\c programs\remove\main.c|4|note: expected 'int' but argument is of type 'int *'|
||=== Build finished: 0 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
nameis not achar. It's a pointer to achar(since it's an array ofchar), which is achar *`.