?
Solved

Reading a file as  and comparing data to a list of known works

Posted on 2000-04-11
1
Medium Priority
?
209 Views
Last Modified: 2010-04-15
I was just wondering if anyone could help me with scanf and strcmp.  What I have to do is read words from a file one a time and compare teh words to a list of words if and if the word I read from the file is one of the words in my predefined list them I increase its counter.  I was just wondering if someone could give a short example of how to use scaf and strcmp in a situation similar to this.  I would appreciate it thanks.
0
Comment
Question by:BCBob2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
homer99 earned 200 total points
ID: 2706109
for reading in words from a file you would not use scanf.  scanf is to read in from input stream.

if this is part of your list of words:

char string1[] = "string1";
char string2[] = "string2";
..
..
..

in main program we execute:

main()
{
  FILE *fptr_read;
  char word[MAX_REC_SIZE + 1 ];
  fptr_read = fopen("FILENAME", "r" );
  while( fgets( word, MAX_REC_SIZE + 1, fptr_read ) != NULL )
  {
    if(strcmp(string1,word) == 0 )
      counter++;
  }
..
..
..
this is not the complete solution because it sounds like homework, but this should give you a good idea of what to do.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question