Are there different ways to store long strings(including spacing)?

Go4Expert Member
7Feb2010,01:55   #1
askmewhy25's Avatar
I'm having problems when i use the fgets() and the gets() functions..

Code:
if(sel==1){
                                                 do{
                                                    system("cls");
                                                    printf("Input a string: ");
                                                    scanf("%s",&string[s]);
                                                    s++;
                                                    do{
                                                       system("cls");
                                                       printf("String successfully added\n");
                                                       printf("Enter another string?\n\n");
                                                       printf("1 - Yes\n");
                                                       printf("2 - No\n");
                                                       scanf("%d",&rep);
                                                       }while(rep!=1&&rep!=2);
                                                    }while(rep==1);
                                                 }
Mentor
7Feb2010,13:31   #2
xpi0t0s's Avatar
Your code doesn't use fgets or gets. What is the problem? Does string[s] not contain what you expect? Have you RTFM on scanf?
Contributor
7Feb2010,21:07   #3
Deadly Ghos7's Avatar
Don't use gets() function, its vulnerable.
Code: c
fgets(string,sizeof(string),stdin);
And for scanf(),
Code: c
scanf("%[^\n]",string);
Hope that helps you.