1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
gavmur [86]
3 years ago
11

Write a c program to count the total number of commented characters and words in a c file taking both types of c file comments (

single line and block) into account.
Computers and Technology
2 answers:
Flura [38]3 years ago
4 0

Answer:

The C program for characters will be like the one below:

Explanation:

#include <stdio.h>

#include <stdlib.h>

int main()

{

   FILE * file;

   char path[100];

   char ch;

   int characters, words, lines;

   /* Input path of files to merge to third file */

   printf("Enter source file path: ");

   scanf("%s", path);

   /* Open source files in 'r' mode */

   file = fopen(path, "r");

   /* Check if file opened successfully */

   if (file == NULL)

   {

       printf("\nUnable to open file.\n");

       printf("Please check if file exists and you have read privilege.\n");

       exit(EXIT_FAILURE);

   }

   /*

    * Logic to count characters, words and lines.

    */

   characters = words = lines = 0;

   while ((ch = fgetc(file)) != EOF)

   {

       characters++;

       /* Check new line */

       if (ch == '\n' || ch == '\0')

           lines++;

       /* Check words */

       if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\0')

           words++;

   }

   /* Increment words and lines for last word */

   if (characters > 0)

   {

       words++;

       lines++;

   }

   /* Print file statistics */

   printf("\n");

   printf("Total characters = %d\n", characters);

   printf("Total words      = %d\n", words);

   printf("Total lines      = %d\n", lines);

   /* Close files to release resources */

   fclose(file);

   return 0;

}

Tanzania [10]3 years ago
3 0

#include<stdio.h>

#include<stdlib.h>

int comment1(FILE *fp)

{

   char ch;

   int count=0;

   while(fscanf(fp,"%c",&ch)!=EOF)

   {

       if(ch=='\n')

       {

           return count;

       }

       count++;

   }

   return count;

}

int comment2(FILE *fp)

{

   char ch;

   int count=0;

   while(fscanf(fp,"%c",&ch)!=EOF)

   {

       if(ch=='*')

       {

           fscanf(fp,"%c",&ch);

           if(ch=='/')

           {

               return count;

           }

           count++;

       }

       count++;

   }

   return 0;

}

int main()

{

   printf("Enter the file name:");

   char s[1000],ch,ch1;

   scanf("%s",s);

   FILE*fp;

   fp = fopen(s,"r");

   int count=0;

   while(fscanf(fp,"%c",&ch)!=EOF)

   {

       if(ch=='\"')

       {

           while(fscanf(fp,"%c",&ch)!=EOF)

           {

               if(ch=='\"')

               {

                   break;

               }

               if(ch=='\\')

               {

                   fscanf(fp,"%c",&ch);

               }

           }

       }

       else if(ch=='/')

       {

           fscanf(fp,"%c",&ch);

           if(ch=='/')

           {

               count += comment1(fp);

           }

           else if(ch=='*')

           {

               count += comment2(fp);

           }

       }

   }

   printf("%d\n",count);

   return 0;    

}

You might be interested in
How did<br> technological artifacts evolved over time?
adell [148]
With helping us communicate with each other and around the world with the internet and other different types of things like,Tesla’s,phones,touch screen IPads,even having a built in TV plane
3 0
2 years ago
Which of these port transmits digital video
DaniilM [7]

Answer:

uhm

Explanation:

theres nothing there

7 0
3 years ago
Read 2 more answers
What is the decimal equivalent of 11BA?
allsm [11]

Answer:

To convert hexadecimal number 11BA to decimal, follow these two steps:

Start from one's place in 11BA : multiply ones place with 16^0, tens place with 16^1, hundreds place with 16^2 and so on from right to left

Add all the product we got from step 1 to get the decimal equivalent of 11BA.

Using the above steps, here is the work involved in the solution for converting 11BA to decimal number (Don't forget that we start from ones place to so on...)

Decimal equivalent of "A" = (A) 10 × 16^0 = 10

Decimal equivalent of "B" = (B) 11 × 16^1 = 176

Decimal equivalent of "1" = 1 × 16^2 = 256

Decimal equivalent of "1" = 1 × 16^3 = 4096

Decimal equivalent of "11BA" = 409625617610

11BA = 4538

Here is the final answer, The hexadecimal number 11BA converted to decimal is therefore equal to:

4538

4 0
2 years ago
Qué propiedades del bromato de potasio han hecho que sea el aditivo más usado en la fabricación del pan​
torisob [31]

Answer:

es la capacidad de unir proteínas presentes en la harina

4 0
3 years ago
Just five types of pointing device,list
posledela

Answer:

five types of pointing devices

Explanation:

Ponting devices

Pointing means point something and the pointing devices are the input /peripheral devices those are used to point the pointer on the screen. We do move cursor on the screen to open the files or any icon.

There are many types of pointing devices but these are quite common which are given below

  1. Computer mouse
  2. Finger on touch screen.
  3. Joystick.
  4. Leap Motion.
  5. Light pen (pen)

1.Mouse

Mouse is most common type of input device that is used for pointing the data on the screen. We press it with our hands and keep pointing the things.

There are three types of mouse

  1. optical mouse
  2. wireless mouse
  3. trackball mouse.

2. Finger on touch screen

In this type of movement the fingers are input devices those we use to see the movement of pointer on the screen and this is most common in this century.

3.Joystick.

Joystick is another input device to point the cursor but it is mostly used in games. Children can use it smartly so it is inculcated in games usually.

4. Leap Motion

The Leap Motion (LM) controller is a latest 3D sensing device for hand posture interaction with a computer. It is having the capability sense the location of the fingers of the hands, as well as the palm position.

5.Light Pen

this is another pointing device which is mostly used to highlight and select the data on the screen.

Note: All of these above pointing devices are most common used now a days. These devices are having new  conventions day by day for the ease of user. This era is basically the era of IT ,so the use of computer must be so easy and conventional for the user so, the innovations and improvement in such devices is made side by side.

3 0
3 years ago
Other questions:
  • Which of these is a typographical clue?
    9·2 answers
  • Suppose your friend, who is a small business owner, wants to computerize her business functions such as accounting, payroll, and
    7·1 answer
  • What is a computer briage coures​
    15·1 answer
  • A _____ miniature battery operated transmitter that can be propelled through a non-metallic pipe or purpose of locating
    6·1 answer
  • Can some one help sorry I just so confused on this and I keep failing it I just need the help So choose the best answers
    12·1 answer
  • Which of the following is a career that's indirectly linked to careers in web technologies?
    10·1 answer
  • A __________ search engine focuses on a specific subject.<br><br>answer : Specialized
    8·1 answer
  • Does a 21.6v battery work with a 24 volt controller
    6·1 answer
  • Which is the correct notation to specify the following inheritance?
    8·1 answer
  • Released in 1976, the Apple I was Apple Computer's first product.<br><br> O True<br> O False
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!