Oh I didn't see Click_Here's reply thank you to the both of you. here is my attempt at indenting the code properly
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 200 /*the maximum size of strings*/
#define MAX_CMD_LEN 10/*the maximum size of a command*/
void getString( char* );
void printString (const char *);
void reverseString (const char *str, char *reverse);
int main(void)
{
char command[MAX_CMD_LEN];
char string[SIZE] = "";
char *p;
char newstr[SIZE];
char reverse[SIZE];
int flag=1;
do {
printf("cmd> ");
if(fgets(command, MAX_CMD_LEN, stdin) != NULL){
if((p = strchr( command, '\n')) != NULL)
*p = '\0';
}
if(strcmp(command ,"new")==0) {
getString(string);
}
else if(strcmp(command, "list")==0) {
printString(string);
}
else if(strcmp(command, "rev")==0) {
reverseString(string, reverse);
}
else { //if any command entered besides these 3
printf("Not valid command"); //ERROR CHECK #1
}
}
while (flag==1);
return 0;
}
void getString(char *string)
{
printf("Please enter your string");
fgets(string, SIZE, stdin);
}
void printString(const char *string)
{
if (string && string[0])
{
printf("\n\nHere is the text you entered:\n%s\n", string);
}
else
{
printf("No string entered");
}
}
void reverseString(const char *string, char *reverse)
{
int len =0, i, j =0;
if (string && string[0])
{
while(string[len])
len++;
for(i=len-1;i>=0;i--)
{
reverse[j]=string[i];
j++;
}
reverse[j] = '\0';
printf("%s", reverse);
}
else {
printf("No string entered");
}
}
So if the user writes new and then just presses enter. I would want the program to consider this also empty. How do I make the program ignore the enter sign. I know this is a simple loop i just kind of forgot it.
Thanks guys!