Avatar of mezarati
mezarati asked on

how do i use execvp to word count a file?

hi,
i was wandering how to launch the wc program in linux from a C program using execvp to word count a file?
LinuxLinux OS DevSystem Programming

Avatar of undefined
Last Comment
mezarati

8/22/2022 - Mon
ozo

 char *argv[] = {"wc","-w","file",0};
  execvp("wc",argv);
ASKER
mezarati

can you please elaborate, sorry i am a linux newbie
lets say i wanted a count a file named file.txt, how would i go about doing it?
ASKER CERTIFIED SOLUTION
ozo

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
mezarati

sorry one more thing
i have the file1.txt stored in the same directory as the source code but i get an error message saying it doesn't exist
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ozo

is it in the same directory from which you run the program?
did you add the "1" to the program?
ASKER
mezarati

no i didnt add the 1 and now it works thank you ...