0

First of all, I'm new to C so pardon me if asking too much.

I have a function that tokenize an input by the user so let's say

user input: test -f myFile

then after the tokenize function it becomes

abc[0] = test
abc[1] = -f
abc[2] = myFile

However, at the same time, I also need to use the return value from that input (test) statement whether it is FALSE or TRUE (file exist or not exist).

I did (MY PROBLEM)

if (*abc != '1') {
    printf ("nope.");
}

in hope for telling me first whether that file is valid / exist or not, before I call some other function. However, it says warning comparison between pointer and integer.

My original plan is:

// ask the user for input

// tokenize the input

if (*abc != '1') { // check the return value from the input
        printf ("nope.");
    }

// call another function

Any input why MYPROBLEM doesn't work? How do I execute test after I tokenize?

coava
  • 79
  • 3
  • 9

1 Answers1

0

If you want to check whether anything was added to abc, you would have to initialize your array to NULs prior to calling tokenize and then afterwards, if (**abc == '\0') would tell you that nothing was tokenized.

However, it's probably better for your tokenize function to return a flag that indicates success or failure in addition to populating your array.

As for executing test, you can use the system() function or one of the exec() functions.

Chad
  • 693
  • 5
  • 17