0
/*part of the code i get that output*/

printf("$> ");
fgets(input, SIZE, stdin);

int flag = 0;
stringCounter = 0;

while(isspace(input[0])) {
    fflush(stdin);
    printf("$> ");
    fgets(input, SIZE, stdin);
}

j = 0;

search[j] = strtok(input, " \n");
while(search[j] != NULL) {
    stringCounter++;
    j++;
    search[j] = strtok(NULL, " \n");
}

strcpy(cmdPart, search[0]);
//strspn(cmdPart, "\n") = 0;

for(i = 1; i < stringCounter; i++) {
    strcpy(textPart, search[i]);
}
printf("command %s, textPart %s cmdLength %d ", search[0], textPart, strlen(search[0]));

for(i = 0; i < 13; i++) {
    if(strcmp(cmdPart, cmdArray[i]) == 0) {
        printf("command in the array\n" );
        flag = 1;

        if(strcmp(cmdPart, "exit") == 0) {
            printf("inside exit\n" );
            stringCounter = 0;

            if(iscntrl(textPart[0]) == 0) {
                printf("$> Text found\n");
                printf("$> exit should not be followed by a string\n");
                break;
            }else {
                printf("\n");
                commandListStructPrint(head);
                printf("\n");

                return 0;
            }

Output i get in command prompt

Enter your command :
exit
command exit, text Part └ command Length 4 command in the array
inside exit
Text found
exit should not be followed by a string

I don't understand what the L part is.

enter image description here

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • As this is both an incomplete, unformatted and way too long code, I don't really want to read it. But having weird characters in the output is often indicating an improperly terminated string somewhere. – Eugene Sh. May 31 '22 at 20:01
  • thanks for pointing out at least what i should look for. – Nikos Xatzichristidis May 31 '22 at 20:06
  • 1
    note: https://stackoverflow.com/questions/2979209/using-fflushstdin – Barmar May 31 '22 at 20:40
  • Whatever you have stored in the `textpart` variable is being interpreted as that character according to whatever encoding your terminal is using. – Alexander May 31 '22 at 20:41
  • Your loop that copies to `textpart` is repeatedly overwritring it. What's the point of that? Did you mean to concatenate them? – Barmar May 31 '22 at 20:42
  • When the command is `exit`, there's nothing in `textpart`, since it doesn't have any parameters. – Barmar May 31 '22 at 20:47
  • I didn't think about it . Thanks for the help. The above code is inside a while loop and I want to break the Input in two parts cmd and text part according to what the command is I check the text part below the Code above I probably should use strcpy instead for or at least that's what am thinking right now – Nikos Xatzichristidis May 31 '22 at 20:49

0 Answers0