I'm trying to enter strings to use for a command interface through hyperterminal, but having issues with the second "gets" function. It lets me enter a command of greater than 4 characters and waits for ENTER to move to the next prinf, but once I try and enter the name with the second "gets" function, it immediately moves on once 4 characters have been entered, it will not allow anything greater than 4 characters... it's as if I hit ENTER again. This isn't all of my code, but what should be needed to help determine the issue:
//strcmp definition
int strcmp ( char* first,
char* second
)
{
int RES;
int i;
for(i; i < 20; i++){
if(first[i] == second [i]) RES = 1;
else RES = 0;
}
if(RES) return 0;
if(!RES) return 1;
}
//IN MAIN CODE:
char mkdir [20] = "mkdir";
char fopen [20] = "fopen";
char rmdir [20] = "rmdir";
char rmfile [20] = "rmfile";
printf("\nPlease input the type of command you would like to perform: \n");
gets (CMD);
printf("\nNow enter the name of the file or directory: \n");
gets (NM);
if(!strcmp(CMD, mkdir)){
rc = f_mkdir(NM);
if (rc) die(rc);
}
if((!strcmp(CMD, rmdir)||(!strcmp(CMD, rmfile)))){
rc = f_unlink(NM);
if (rc) die(rc);
}
Awesome, I'll look into both of these. I did notice I had some declarations and things wrong, wrote this in a few minutes trying to get a quick test in on an embedded system.
I had to define strcmp because it didn't appear to be an included function. I know it is in C++ but I'm rather new to C so I wasn't sure. Also, I'm using Keil uVision 3, not sure if it has different libraries?
Johnnystarr is right. Coding conventions will help with code readability, to some extent. However, coding conventions are more strictly used when working in teams, as it can become confusing to other team members when a convention changes.