Solved

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

Posted on 2000-04-11
1
204 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
1 Comment
 
LVL 2

Accepted Solution

by:
homer99 earned 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
memory leak detection 9 101
How to Post data to a PHP webpage from an embedded C application using TCP/IP? 5 242
Problem to ASCII 1 215
Secondary drive is failing... D Volume 11 47
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

679 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