Here is my header file code (structure.h)
And here is my main program codeCode:struct user { int userId; char firstname[20]; char lastname[20]; int age; float weight; };
Code://Programming in C (Structural) /* * * @author Dushyant Kaushik * */ #include <stdio.h> #include <stdlib.h> #include "strucutre.h" char name[25]; void addusr_Wizard(char name[25]); int main(void) { system("clear"); char c; printf("Want to add a user? (Y OR N)"); scanf("%c", &c); if(c == 'Y') { printf("\nEnter name of the user: "); scanf("%s", &name); addusr_Wizard(name); } else { printf("OK! As you wish!"); break; } getchar(); return 0; } void addusr_Wizard(char name[25]) { struct user name; name.firstname = name; printf("Enter last name of the user: "); scanf("%s", &name.lastname); printf("Enter age of user: "); scanf("%d", &name.age); printf("Enter user id: "); scanf("%d", &name.userId); printf("Enter weight of the user: "); scanf("%f", &name.weight); exit(0); }
I am getting these arrays in NetBeans
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/iexploit/NetBeansProjects/CProgramming'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cprogramming
make[2]: Entering directory `/home/iexploit/NetBeansProjects/CProgramming'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/newmain.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/newmain.o.d" -o build/Debug/GNU-Linux-x86/newmain.o newmain.c
newmain.c: In function ‘main’:
newmain.c:28:9: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[25]’ [-Wformat=]
scanf("%s", &name);
^
newmain.c: In function ‘addusr_Wizard’:
newmain.c:43:17: error: ‘name’ redeclared as different kind of symbol
struct user name;
^
newmain.c:41:25: note: previous definition of ‘name’ was here
void addusr_Wizard(char name[25])
^
newmain.c:45:20: error: incompatible types when assigning to type ‘char[20]’ from type ‘struct user’
name.firstname = name;
^
newmain.c:47:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[20]’ [-Wformat=]
scanf("%s", &name.lastname);
^
make[2]: *** [build/Debug/GNU-Linux-x86/newmain.o] Error 1
make[2]: Leaving directory `/home/iexploit/NetBeansProjects/CProgramming'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/iexploit/NetBeansProjects/CProgramming'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 260ms)