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

The Archive Base Latest Questions

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

#include<stdio.h> /* this is a lexer which recognizes constants , variables ,symbols, identifiers ,

  • 0
#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=0,j;
    char a,b[20],c[30];
    FILE *fp1,*fp2;
    c[0]='"if";
    c[1]="then";
    c[2]="else";
    c[3]="switch";
    c[4]="printf";
    c[5]="scanf";
    c[6]="NULL";
    c[7]="int";
    c[8]="char";
    c[9]="float";
    c[10]="long";
    c[11]="double";
    c[12]="char";
    c[13]="const";
    c[14]="continue";
    c[15]="break";
    c[16]="for";
    c[17]="size of";
    c[18]="register";
    c[19]="short";
    c[20]="auto";
    c[21]="while";
    c[22]="do";
    c[23]="case";
    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;

        }
        else
        {
            for (j=0;j<23;j++)
        {
            if(c[j]==b)
            {
                fprintf(fp2, "%.20s\n", c[j]);
                continue ;
                        }
            b[i]='\0';
            fprintf(fp2, "%.20s\n", b);
            i=0;
            continue;
        }
    //else if 
    //{

        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 '
        */
    }
fclose(fp1);
fclose(fp2);
return 0;
}

This is my c code for lexical analysis .. its giving warnings and also not writing anything into the lext file ..

  • 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:12:58+00:00Added an answer on May 14, 2026 at 7:12 am

    char c[30]; declares an array of 30 char, i.e. 30 byte long chunk of memory. So an assignment like the c[0] = "if"; tries putting a pointer into a char-sized integer.

    What you probably want there is char* c[30]; – an array of 30 pointers.

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

Sidebar

Related Questions

I have this code: #include <stdio.h> #include <stdlib.h> #include <signal.h> // Define the function
I just saw this here #include <stdio.h> int main(int argc, char *argv[printf(Hello, world!\n)]) {}
I see a code as below: #include stdio.h #define VECTOR_SIZE 4 typedef float v4sf
I'm newbie to flex. I'm trying to write a simple re-entrant lexer/scanner with flex.
I am trying to write this simple image modifier program in c++ with opencv
I am trying to compare to a defined constants in C, and I have
My program takes two files with words sorted as parameter and performs the mixture
The following C problem searches s1 inside s2 and returns the position that s1
I am trying to use 'GetModuleFileNameA' but I keep getting the error 'c4430: missing
I have a website where each webpage is compiled into a binary (I have

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.