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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:57:06+00:00 2026-06-18T04:57:06+00:00

Ok so i am writing a C program. The program is simple enough, when

  • 0

Ok so i am writing a C program. The program is simple enough, when i run the program i give it a few parameter Ex ./proj1 cat hat bat, so then it asks me to input a list of words the program gives counts of how many times “cat”, “hat”, and “bat” occurs in that list.
I have the program working great.

Example 
./pro1 cat hat bat
cat
.

(the program recognized a “.” as the end of input)

Result:
cat:1
hat:0
bat:0

ok so my program runs perfectly in every test case i can think of, but I have to pass a series of tests that my professor has mas made.
here is the code of that test.

char *args[] = {"./main", "cat", "hat","bat",NULL};
char *result[] = {"Looking for 3 words\n",
  "Result:\n",
  "cat:1\n",
  "hat:0\n",
  "bat:0\n"};
FILE *out;
FILE *test;
test=fopen("test","w");
int i;
char *buffer=malloc(100*sizeof(char));

out = fopen("smp0.in", "w");
fprintf(out, "cat\n");
fprintf(out, ".\n");
fclose(out);

freopen("smp0.in", "r", stdin);


freopen("smp0.out", "w", stdout);

quit_if(main(4, args) != EXIT_SUCCESS);

fclose(stdin);
fclose(stdout);

out = fopen("smp0.out", "r");


for (i = 0; i < 5; i++) {
    quit_if(fgets(buffer, 100, out) == NULL);
    quit_if(strcmp(buffer, result[i]));
}


fclose(out);
return EXIT_SUCCESS;
 }

ok so sending the quit_if() is the method that makes it fail. specifically

   quit_if(strcmp(buffer, result[i]));

My output when i run the program is exactly as described. But between freopen() diverting stdout to a file and then reading it back it has changed somehow.

  Result:
  cat:1
  hat:0
  batÿ:0

is what the output becomes, but it is not like that before the file write and read, and for some reason it is always that weird y character.

any advice would be greatly appreciated.
Sorry for not posting more code but it’s because it is a school project.
I am confident that it is the test that is wrong in some way and not my code, fixing the test is part of the project as well.

  • 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-18T04:57:07+00:00Added an answer on June 18, 2026 at 4:57 am

    See this answer to a previous question:

    https://stackoverflow.com/a/4906442/2009431

    It seems that when the dot is read back in from your stdin file, it has an EOF token appended (makes sense) that would not normally be part of the user’s input. Then, somehow (not sure since we can’t see your code) your main() function is appending that EOF character onto “bat” in the form of that weird y character (see linked answer for details on why).

    If I’m right, maybe this could be considered a bug in the test?

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

Sidebar

Related Questions

I'm writing a simple program that will run entirely client-side. (Desktop programming? do people
When writing a simple program for a POSIX-compliant OS which accepts input and produces
I'm writing simple program to communicate between smart devices and I receive 11001 when
I'm writing a simple program to convert text to strings. One quick question, how
I am writing a simple program to filter out stock quotes from a given
I'm writing a simple program. There is only one class in it. There is
I am writing a simple program, which is trying to find next palindrome number
I'm writing a simple program to call a Java function from my C program.
So I was writing this simple program to calculate the day of any date
I am new to C and writing a simple program to display the byte

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.