Novice need your help! 
Author Message
 Novice need your help!

Hi, everybody.

I am a beginner learning c and encounterd the following problem

If a text file is provided by a user, and I need to write a
program to search a particular pattern specified by a user
and then print out the corresponding lines.

I think what I need to do is to store the text file first, and then
search the pattern in each of the element in this array. Hence, I store
it as a arrays of strings, however; I am not so sure how to use check
EOF and how to declare array of strings?

Could you tell me how to implement it using arrays of strings or it
is much better to use pointers?

Or is there any better method to implement this task?
Love to hear any suggestion!

Please put your answers in the news group.

/************************************************************
 *
*
 * This program read a text file and then stored the
texts                                   *
 * as arrays of strings, and then print lines on the
screen                                    *
 *
*
 ************************************************************/

#include <stdio.h>
#define MAX_INPUT_LENGTH 200

main()
{
 int j;
      typedef char strings[80];
      strings line[MAX_INPUT_LENGTH];
 int i=0;
 while (fgets(line[i], sizeof(line[i]), stdin)!=NULL)
        {
  sscanf(line[i], "%s", &line[i]);
  i++;
 }

 for(j=0; j<i; j++)
   printf("The string is %s\n", line[j]);

Quote:
}



Wed, 09 Feb 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Novice needs quick help q/ gets();

2. non-novice needs help with variable arguements va_arg to a function

3. novice needs help with recursion

4. Complete novice needs help!

5. A novice needs help...

6. Novice needs Help using a GNU lib on SGI

7. Novice need help

8. Novice Q: need help using time

9. Novice needs help

10. Novice programmer needs help!

11. Novice C Programmer needs help.

12. Novice - help needed

 

 
Powered by phpBB® Forum Software