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 7064955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:53:51+00:00 2026-05-28T04:53:51+00:00

I am trying to read words and numbers from a space and tab delimited

  • 0

I am trying to read words and numbers from a space and tab delimited text file. I need to identify lines which contain “Step” and “False”. I also need to store each word or number separately so that some can be thrown out later.

I am having trouble trying to write the part of the code which identifies “False” at the end of a line. I need the code to recognize that it has reached False and break the for loop.

Note: It is designed so that you input your own path. This portion works. Also, I have read that fscanf is much harder to use than fgets and fputs, but the data files i am reading are very consistent in format. This seems to work well for my purposes, as some entries will need to be doubles.

    int j;
    int k;
    char i[4];                       
    char File_path[40];
    char dummy;
    char stuff[7] = "False"

    printf("Input Path: ");
    scanf("%s", &File_path);
    printf("Reading:  %s\n\n",File_path);
    FILE *fp;
    fp=fopen(File_path, "r");
    for(j=0; j<7 && i != stuff; j++)
    {
        fscanf(fp,"%s",i);
        fprintf(stdout,"Read:  %s\n",i);
    }
    fclose(fp);

The file I am reading is:

True.0 kinda false False False

This returns:

Reading:  c:\\Data\\1.txt

Read:  True.0
Read:  kinda
Read:  false
Read:  False
Read:  False
Read:  False
Read:  False

I have tried changing stuff to “False” and I get the same result.

  • 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-28T04:53:52+00:00Added an answer on May 28, 2026 at 4:53 am

    You can’t compare strings that way in C. You need to use strcmp() or strncmp() to do that:

    for (j = 0; j < 7 && strcmp(i, stuff); j++)
    

    That loop conditional will break the first time i points to "False". You also need to make i larger – you’re going to overflow that buffer on the first read in your example.

    Editorial – you really do probably want to use fgets() and strtok() or one of its relatives to work through this stuff.

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

Sidebar

Related Questions

I am trying to read a text file from raw folder, and it works
I am trying to read a large list of English words from a text
I am trying to read a number from a file with Get-Content and adding
I'm trying to read base block from windows HIVE file. First 4 bytes of
I am trying to read the input from a keyboard which i will use
I am Trying to read data from text files and save tokens in SQLite
Basically I am trying to read a block of data from a file that
I'm trying to grab 5 lines by their line numbers from a large (>
I'm trying to read from a file, but the only thing I get on
What I am trying to do is, Open the word file, read a line,

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.