Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6776341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:00:58+00:00 2026-05-26T16:00:58+00:00

Sorry for asking very simple question.I’m new to coding. Input txt file 5,3 001

  • 0

Sorry for asking very simple question.I’m new to coding.
Input txt file

5,3
001
110
111
110
001

I need to print the output as

U1: 001
U2: 110
U3: 111
U4: 110
U5: 001

Upto now I was able to print the contents with this:

  #include <stdio.h>
  void main() {
    FILE *fopen(), *fp;
    int c;

    fp = fopen("read.txt","r");
    c = getc(fp) ;

    while (c!= EOF) {
      putchar(c);
      c = getc(fp);
    }

    fclose(fp);
  }

Can Anybody tell how should I proceed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:00:59+00:00Added an answer on May 26, 2026 at 4:00 pm

    Most of your work is done inside the while loop.
    But you’re not doing enough work …
    a) you need to count lines
    b) you need to print the "U#"

    Suggestion: create a variable for the line counting business and rewrite your loop to consider it. Here’s a few snippets

    int linecount = 0;
    

    printf("U%d: ", linecount)
    

    if (c == '\n') linecount += 1;
    

    Oh! You really shouldn’t add the prototype for fopen yourself. It is already specified with #include <stdio.h>.

    And well done for declaring c as int. Many people do the error of declaring it char which is incompatible with EOF and all the range of characters

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I might be asking a very basic question and I am sorry for that.
I am very new to PDO, sorry if you feel I am asking stupid
I am learning Haskell. I'm sorry for asking a very basic question but I
Sorry if this sounds like a really stupid question, but I need to make
Sorry for asking this question, but I searched all Java-related questions, but I got
Sorry for asking what seems like such an obvious question. I have an adapter
Sorry for asking a basic question like this but I've been reading on this
Preface: I'm very new to objective-c and I am doing simple exercises to learn
Sorry for asking a question about something I don't know much about, but I've
Sorry for asking such a newbie question, I know it makes a few of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.