Get First and Last name 
Author Message
 Get First and Last name

Can anyone tell me how to get{*filter*}and last name together?

I used
for(i=0; i<3; i++)
{
     fscanf(fp, "%[\t]" name[i]);

Quote:
}

FILE
Tom  Moore             12  34
Mary  Jones      45  78
Peter  Pham         20  45

#include<stdio.h>
#include<stdlib.h>

#define ROW 3
#define COL 3
#define SIZE 30

int main(void)
{
 FILE *fp;

    int scores [ROW][COL];
 char name  [ROW][SIZE];
    int i, j;
    int counter = 0;

 if((fp=fopen("LAA.TXT", "r")) == NULL)
 {
  printf("\nCANNOT opening file LAB1.TXT\n");
  exit(1);
 }

 fscanf(fp, "%[\t] %lf", &name[counter], &scores[ROW][COL]);

 for(i=0; i<ROW; i++ )
 {
  int sum=0;
  for(j=0; j<COL; j++)
  {

       sum += scores[i][j];
  }
     printf("\t\t%s\t%7.2lf ", name, sum);
  printf("\n");
 }
 return 0;

Quote:
}

OUTPUT

Tom  Moore      46
Mary  Jones      123
Peter  Pham      65



Sun, 06 Jul 2003 18:23:51 GMT  
 Get First and Last name
On Wed, 17 Jan 2001 02:23:51 -0800, Simon Ng

Quote:

>Can anyone tell me how to get{*filter*}and last name together?

>I used
>for(i=0; i<3; i++)
>{
>     fscanf(fp, "%[\t]" name[i]);
>}

If you can get a guarantuee that the tab character will never be used
within the name field, your attempt almost works.
To read characters from fp until you find a tab, and store that in
name[i], you should use:
  fscanf(fp, "%[^\t]", name[i]);

Your code reads only the tab characters into name

Bart v Ingen Schenau
--
Remove NOSPAM to mail me directly
FAQ for clc: http://www.*-*-*.com/ ~scs/C-faq/top.html



Mon, 07 Jul 2003 05:43:16 GMT  
 Get First and Last name

<snip>

I made a number of comments on your program the last time you posted
it. Do you actually bother to read the replies to your posts?

Sent via Deja.com
http://www.deja.com/



Mon, 07 Jul 2003 19:35:34 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. First / Last Day of Week

2. REQ: advice for 2nd to last assignment for my first C class

3. AddNew() Update() over writes either first or last record

4. Making last line of text first visible in edit box

5. Making last line of text first visible in edit box

6. list[first,last) with ifstream_iterator

7. Help...Getting the font file name from the typeface name

8. Help...Getting the font file name from the typeface name

9. Getting Universal Name From Path Name

10. getting CDB file name from Table name

11. Sorting a last names that are contained within a structure

12. Getting Last 3 Chars of Char*

 

 
Powered by phpBB® Forum Software