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

  • Home
  • SEARCH
  • 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 736823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:38:58+00:00 2026-05-14T07:38:58+00:00

this code is the base of lexer , and it does the basic operation

  • 0

this code is the base of lexer , and it does the basic operation of removing the whitespaces from a source file and rewrites it into another file with each word in separate lines .
But i am not able to understand why the file lext.txt not getting updated?

#include<stdio.h>

/* this is a lexer which recognizes constants , variables ,symbols, identifiers , functions , comments and also header files . It stores the lexemes in 3 different files . One file contains all the headers and the comments . Another file will contain all the variables , another will contain all the symbols. */

int main()
{
    int i;
    char a,b[20],c;
    FILE *fp1,*fp2;

    fp1=fopen("source.txt","r"); //the source file is opened in read only mode which will passed through the lexer
    fp2=fopen("lext.txt","w");  
    //now lets remove all the white spaces and store the rest of the words in a file 

    if(fp1==NULL)
    {
        perror("failed to open source.txt");
        //return EXIT_FAILURE;
    }
    i=0;
    while(!feof(fp1))
    {


        a=fgetc(fp1);

        if(a!="")
        {
            b[i]=a;
        printf("hello");
        }
        else
        {

            b[i]='\0';
            fprintf(fp2, "%.20s\n", b);
            i=0;
            continue;
        }
        i=i+1;                  

        /*Switch(a)
        {
            case EOF :return eof;
            case '+':sym=sym+1;

            case '-':sym=sym+1;

            case '*':sym=sym+1;

            case '/':sym=sym+1;

            case '%':sym=sym+1;

            case '
        */
    }
return 0;
}
  • 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-14T07:38:58+00:00Added an answer on May 14, 2026 at 7:38 am

    You write to the file only when this condition fails:

    if(a!="") // incorrect comparison..warning: comparison between pointer and integer
    

    which never does so you never go to the else part.

    Change the test to:

    if(a!=' ')
    

    EDIT:

    When you reach the end of the file you just terminate the program without writing what is in the array b. So you need another fprintf after the while loop:

    } // end of while loop.
    b[i]='\0';
    fprintf(fp2, "%.20s\n", b);
    

    Alright here goes the code thats tested and works fine 🙂

    while(1)
    {
        a=fgetc(fp1);
        if(feof(fp1))
            break;
    
        if(a!=' ')
            b[i++]=a;
        else {    
            b[i]='\0';
            fprintf(fp2, "%.20s\n", b);
            i=0;
        }    
    }
    b[i]='\0';
    fprintf(fp2, "%.20s\n", b);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have to specify an encoding. Add the following line… May 16, 2026 at 4:52 pm
  • Editorial Team
    Editorial Team added an answer Bind is probably the best choice. The guides you're referring… May 16, 2026 at 4:52 pm
  • Editorial Team
    Editorial Team added an answer So I'm trying to clean-up the mess. I started using… May 16, 2026 at 4:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Looking at an open source code base i came across this code: #include StableHeaders.h
I came across this code while working through code-analysis warnings on our code base.
I have this program that should execute a piece of code base on the
I have the following HTML (excerpt from larger code-base) <div class=diary-event ui-corner-all title=[title]> <span
I have a code-base that I'm looking to split up and add to by
Can anyone explain why this code gives the error: error C2039: 'RT' : is
Consider this (horrible, terrible, no good, very bad) code structure: #define foo(x) // commented
Problem: I am using a big C/C++ code base which works on gcc &
In our C++ code base we keep 99 column lines but 79-some-odd column multiline
I am migrating my app code base to iPhone SDK 4. In one 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.