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

askmewhy25's Avatar, Join Date: Jan 2010
Go4Expert Member
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);
                                                 }
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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?
Deadly Ghos7's Avatar, Join Date: Dec 2009
Contributor
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.