C Program to Count the Total Number of Words in the Sentence using Command Line Argument
This C Program counts total number of words in the sentence using command line argument.
Here is source code of the C Program to Count the total number of words in the sentence using command line argument. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Count the Total Number of Words in the Sentence
* using Command Line Argument
int main(int argc,char*argv)
int i =0;
/* If no sentence is given in the command line */
printf("\n No sentence given on command line");
printf("\nThe words in the sentence are:");
* From argv to argv[argc -1] calculate the number of arguments
for(i =1;i < argc;i++)
printf("\n\nTotal number of words:");
printf(" %d", argc-1);
$ gcc arg1.c
$ a.out Welcome to C Class
The words in the sentence are:
Total number of words: 4
No sentence given on command line
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Manish Bhojasia, a technology veteran with 17+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below.
Practice Interview Questions & Answers, Quizzes, Objective, Multiple Choice Aptitude Tests for Freshers and Experienced People in these topics -
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel & Device Driver Programming. Our Founder has trained employees of almost all Top Companies in India. Here are few of them: VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium Networks, ST Microelectronics, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Northwest Bank, Mphasis, Tata Elxsi, Tata Communications, Mindtree, Cognizant, mid size IT companies and many Startups. Students from top Universities and colleges such as NIT Trichy, BITS Pilani, University of California, Irvine, University of Texas, Austin & PESIT Bangalore have benefited a lot from these courses as well. The assignments and real time projects for our courses are of extremely high quality with excellent learning curve.
Register for Expert Level Training Classes by our Founder & CTO. Alternatively, call us for your Corporate Training or College Training needs.