Name: derp 2012-04-25 16:03
Anyone have any idea why this won't run? I've been trying to fix it for hours and can't find the issue. I created a different version utilizing functions from <string.h>, but I'd like to see if it can be built to run without it, while still having the readArray function I've built using getchar
1 //Structures. Contain members.
2
3 #include <stdio.h>
4
5 void readArray(char []);
6
7 struct Student
8 {
9 int id;
10 char name[30];
11 float final;
12 }
13
14 main()
15 {
16 struct Student st;
17
18 printf("Enter student id: ");
19 scanf("%d", &st.id);
20 printf("Enter name: ");
21 readArray(st.name)
22 printf("Enter final score: ");
23 scanf("%f", &st.final);
24
25 printf("The ID is: %d\n", st.id);
26 printf("The name is: %s\n", st.name);
27 printf("The final score was: %.2f\n", st.final);
28 }
29
30 void readArray(char st.name[])
31 {
32 char c;
33 int i;
34
35 for(i=0; (c=getchar()) != '\n'; i++)
36 {
37 st.name[i] = c;
38 }
39 st.name[i] = '\0';
40 }
THE ERROR:
studentstruc.c: In function âmainâ:
studentstruc.c:22:2: error: expected â;â before âprintfâ
studentstruc.c: At top level:
studentstruc.c:30:23: error: expected â;â, â,â or â)â before â.â token
1 //Structures. Contain members.
2
3 #include <stdio.h>
4
5 void readArray(char []);
6
7 struct Student
8 {
9 int id;
10 char name[30];
11 float final;
12 }
13
14 main()
15 {
16 struct Student st;
17
18 printf("Enter student id: ");
19 scanf("%d", &st.id);
20 printf("Enter name: ");
21 readArray(st.name)
22 printf("Enter final score: ");
23 scanf("%f", &st.final);
24
25 printf("The ID is: %d\n", st.id);
26 printf("The name is: %s\n", st.name);
27 printf("The final score was: %.2f\n", st.final);
28 }
29
30 void readArray(char st.name[])
31 {
32 char c;
33 int i;
34
35 for(i=0; (c=getchar()) != '\n'; i++)
36 {
37 st.name[i] = c;
38 }
39 st.name[i] = '\0';
40 }
THE ERROR:
studentstruc.c: In function âmainâ:
studentstruc.c:22:2: error: expected â;â before âprintfâ
studentstruc.c: At top level:
studentstruc.c:30:23: error: expected â;â, â,â or â)â before â.â token