Hello to all,
For the following code, I want to add a test so that if the user inputs anything that isn't an integer , he/she will receive an error message as opposed to a segmentation fault error which is happening now.
Here is the code:
Code:
else if ((strcmp ( command, "show")) == 0 )
{
list_num = atoi(strtok(NULL, " \n\t")) ;
int x ;
int line_count = 1 ;
for(x = 0; x<strlen(loadedSequences[list_num-1].data) ; ++x) // print 60 letters per line.
{
if(x==0)
{
printf("%10d",line_count) ;
}
if((x%10 == 0))
{
printf(" ") ;
}
if((x%60 == 0) && (x != 0))
{
printf("\n%10d ",(line_count+x)) ;
}
printf("%c", loadedSequences[list_num-1].data[x]) ;
}
printf("\n") ;
}
The code works fine otherwise. Any suggestions would be great.