Halo all,
I've made a simple code in which i'm trying to read a string and compare it with another string. The problem is that i'm not able to get the string from the user neither from scanf nor from fgets. I get run time error. One more thing how can i assign the array size in the second argument of fgets when i'm using pointer format of a string.
Also what are the advantages of declaring a string as "char *s" rather than "char s[20]" with respect to memory? I mean if the string is of 10 chars then in the latter form 10 bytes will get wasted, does the same happens in the former also?Code:#include<stdio.h> #include<string.h> #include<conio.h> int main(void) { char *p="hello",*q; int x; printf("Enter the string"); //scanf("%s",*q); I did this one time fgets(q,10,stdin);// At the other time i did this x=strcmp(p,q); if(x==0) { printf("YES"); } else { printf("NO"); } getch(); }