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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:03:17+00:00 2026-06-09T22:03:17+00:00

I am greping and awking some text from a file and writing it to

  • 0

I am greping and awking some text from a file and writing it to another one.

When I am trying to open and read log_2 to do something, it works fine in case the grep returned some string.

But if grep itself dint return anything , my code is going into an infinite loop. I tried printing the character being read in the loop, it prints a ‘ ÿ ‘ infinitely.

system("egrep 'Security = |State = ' log.txt > log_1.txt");
system("awk -F ' Security = | State = { Interface=' '{print $2}' log_1.txt > log_2.txt ");

// The exact strings to be greped and awked are different. Cant write them here.    

FILE *pReadFile;
char cTemp;

pReadFile=fopen ( "log_2.txt" , "r+");

if (pReadFile==NULL )
{
    std::cout << ("Error opening Config file");
    fclose(pReadFile);
    return ;
}

cTemp = fgetc (pReadFile);

if(cTemp == EOF)    
return ; 


while( cTemp != EOF )
{
      // Do Something

      cTemp = fgetc (pReadFile);
}

Can someone explain ?


Just to add in case someone is having similar issue, this code works fine on Intel based Ubuntu systems, but Freescale ones with Ubuntu will cause a problem. So be careful, and always use int to be safe.

  • 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-06-09T22:03:19+00:00Added an answer on June 9, 2026 at 10:03 pm

    EOF is an int not a char.

    char cTemp;
    

    should be:

    int Temp;
    

    See here for the explanation:

    http://c-faq.com/stdio/getcharc.html

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

Sidebar

Related Questions

I'm trying to collect some advices on error logging in java. My log file
I have a list of strings - something like mytext = ['This is some
I have a program which outputs various results after greping strings from a log
I'm trying to add a line of text to the middle of a text
Need some help designing a bash script for grepping IP addresses from auth.log and
abc=123 dabc=123 abc=456 dabc=789 aabd=123 From the above file I need to find lines
I've recently been trying to create units tests for some legacy code. I've been
Currently I'm doing some unit tests which are executed from bash. Unit tests are
I have one huge file (over 6GB) and about 1000 patterns. I want extract
I'm trying to enable debugging options in MuPDF. For some reason they have used

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.