Code:
#include <stdio.h>
char stringA[256];
char stringB[256];
char *pointerA;
char *pointerB;
char selection;
char selection2;
int main(){
pointerA = stringA;
pointerB = stringB;
void getFirstString(char *pointer);
void getSecondString(char *pointer);
void appendString(char *A, char *B);
getFirstString(pointerA);
getSecondString(pointerB);
appendString(pointerA,pointerB);
return 0;
}
void getFirstString(char *pointer){
void getValue(char *ptr);
do{
printf("What is the first string : ");
getValue(pointer);
printf("So your 1string is ");
puts(pointer);
printf(" Is this correct? Y or N : ");
scanf("%c",&selection);
}while(selection != 'Y');
}
void getSecondString(char *pointer){
void getValue(char *ptr);
do{
printf("What do you wish to append?");
getValue(pointer);
printf("So your 2string is ");
puts(pointer);
printf(" Is this correct? Y or N : ");
scanf("%c",&selection2);
}while(selection2 != 'Y');
}
void getValue(char *ptr){
fgets(ptr,120,stdin);
}
For some reason in getSecondString, the printf statement 'So your 2string is' executes before the fgets statement, looking like:
Code:
What do you wish to append?So your 2string is
Anyone know why?
Bookmarks