Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 1st, 2006, 9:11 AM   #21
beginnerCCC
Newbie
 
Join Date: Sep 2006
Posts: 29
Rep Power: 0 beginnerCCC is on a distinguished road
now i have this code.
but i can only read the first column.
what should i do to read the rest?
#include <stdio.h>
#include <string.h>

#define ROW 762
#define COL 7


typedef struct{
	int day;
	char month[3];
	int year;
	}DATE;
	
typedef struct{
	char filename[20];
	DATE date;
	float third;
	float forth;
	float fifth;
	float ClosePrice;
	float seventh;
	}BHP;

int main(void)
{
	FILE* infile;
	 char buffer[ROW];
	
	int i,j,k;
/*	  struct BHP result[100];*/
	char delims[] = ",";
    char *result = NULL;
	
	
	infile = fopen("bhp.csv","r");
	if (infile == NULL)
	{
		printf("Error opening file!!!\n");
		return 0;
	}
for(i=0;i<ROW;++i)
	{
	fgets(buffer,ROW,infile);
	}

/* spliting the columns*/
 
for(i=0;i<ROW;++i)
	for(j=0;j<COL;++j)
{
	result = strtok(buffer, delims );
	
	/*fscanf(infile,"%f",&result);
	  while(!feof(infile))*/
		{
			printf("result is \"%s\"\n",result);
		}
}

free(buffer);
fclose(infile);
	







	return 0;
}
beginnerCCC is offline   Reply With Quote
Old Oct 1st, 2006, 10:26 AM   #22
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You need to start paying attention. ROW, which happens to be the number of lines in this one particular file, has nothing to do with the maximum number of characters you want to read in one fgets operation. Read the documentation on fgets. ROW, as a number, will probably work very well in that job, but that job has nothing to do with the number of rows (records, lines) in the file. If you were confused before, you are confusing yourself worse, now. You are then reading ROW lines, one at a time, each one destroying the one from before. You're not checking for success. A file with fewer than ROW lines will kick you square in the cojones. You still don't seem to have a concept of the difference between a record and a field. In short, you need to get serious. We help with homework here, we don't DO homework here (it's against the rules). Read my previous post concerning records and fields. If you don't get that, you can't begin.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 9:55 AM
How to read unknown total of int data from text file to a 2-dim array in C ladyscarlet99 C 2 Sep 9th, 2005 3:28 AM
Installing IPB 2.03 bh4575 Other Web Development Languages 0 Apr 23rd, 2005 3:36 AM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 10:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 5:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC