I am trying to accept a multi word string from user input on the console. My code looks like..
char fullPath[150];
char fileName[30];
char serviceName[50];
int portNum[6];
char ip[16];
printf("Enter full path where you want the file to be.\nExample: C:\\Users\n");
scanf("%s", fullPath);
CheckDirectory(fullPath);
printf("Enter what you want the file to be named. \nExample: test.exe\n");
scanf("%s", fileName);
CopyNewFile(fullPath, fileName, argv[0]);
printf("Enter RunKey Service Name:\n");
fgets(serviceName,49,stdin);
printf("Enter callback IP:\n");
scanf("%15s", ip);
printf("Enter callback port:\n");
scanf("%5s", portNum);
The Issue I run into is...
Enter RunKey Service Name:
Enter callback IP:
192.168.100.10
Enter callback port:
443
As you can see, it skips over the part where I should input the service name. I have tried using scanf like the other two inputs and I have tried using regex expression (%[^\n]) as well and it does not grab the entire line either.
Edit: After more testing I am able to input into the Service name if I move the printf and scanf above the printf that asks where the file should be.