You have already got many suggestion to check your program for warnings and errors.
Check warnings and errors of your program : https://onlinegdb.com/By1VeOK1d
main.c:20:9: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
main.c:22:9: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
main.c:25:12: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
main.c:26:14: warning: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast [-Wint-conversion]
/usr/include/string.h:144:12: note: expected ‘const char *’ but argument is of type ‘char’
main.c:44:12: warning: unknown escape sequence: 'C'
All of the above warnings will be cleared just by making two changes to your code
line 11 change char x;
as char* x;
line 44 change printf("
Choose input = ");
as printf("
Choose input = ");
Moving on to your code correctness, your function inputdata()
is depending on global variable a
and the loop for(i=0; i<a; i++){
is never true because i < a
will never be true, since a
is global (default value 0).
Which leads to execution of other statements in an undefined way.
you are directly reading your input into structure scanf("%s", batas[a].nim);
, instead read into a local variable like char temp[30]
, then add it your batas
and continue checking for the existence of your string from next input.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…