GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Apr-2004, 18:39
amir_b amir_b is offline
New Member
 
Join Date: Feb 2004
Posts: 27
amir_b is on a distinguished road

Project


Hello!

I need help about this project. I need to create text file delimit each field by a comma. Write C program that will read created file to populate a struct, reorder date and delete flag should be initialized to zero, write the structure to a binary file opened in w+ mode. After all records have been read from the text file and written to the binary file list out the records in sequential order from the binary file.
I don't know guys what is going on here. I have created file that has following data:

Part ID Description Unit price Qonhand ROP ROQ

These are labels and data goes below. Somehow I've got the following codes but it is very hard for me to figure it out. I need your help if you could point in this code what is going on, and what am I supposed to do? I appreciate every effort to help me solve this confusion.

Thanks.

CPP / C++ / C Code:

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include "C:\Documents and Settings\My Documents\CrtUtil.h"
FILE *inPut, *outPut;
struct date{
	int month, day, year;}reordDate;
	struct date blankDate = {0,0,0};
struct invent{
	char partId[6+1];
	char partDesc[25+1];
	double unitPrice;
	int quanOnHand;
	int reordPoint;
	int reordQuant;
	struct reordDate;
	int delFlag;
}item;

int i, j, goodrd = 1;
int delFlag;

char ch, lastch = ' ';
char tempLine[40];
char bufferLine[80];

typedef struct{
	char partid [6+1];
	long recoffst;
}INDEX;
INDEX indxpt [100];

main()
{
	if((inPut = fopen("C:\\Documents and Settings\\10111260\\My 
Documents\\part.txt","r"))!= NULL)
		if((outPut = fopen("C:\\Documents and Settings\\My 
Documents\\invent.dat","wb+"))!= NULL)
		
		{if (fgets(bufferLine, 80, inPut)==NULL)
			goodrd = 0;
		else
			puts(bufferLine);
		
		while(goodrd)
			{lastch = ' ';//lastch = NULL
		    reordDate = blankDate;
			delFlag = 0;//delFlag is set to 0
		
			for( i = 0, j = 0; lastch != ','; i++, j++)
			{sscanf(&bufferLine[i], "%c",&ch);
					if(ch != ',')
			tempLine[j] = ch;
		lastch = ch;}//lastch = character read
		for( j = 0; lastch != ','; j++, i++)
		{sscanf(&bufferLine[i], "%c",&ch);
			if(ch != ',')
		tempLine[j] = ch;
		lastch = ch;}
				
		for( j = 0,; lastch != ','; j++, i++)
		{sscanf(&bufferLine[i], "%c",&ch);
		if(ch != ',')
		tempLine[j] = ch;
		lastch = ch;}
		for( j = 0,lastch = NULL; lastch != ','; j++, i++)
		{sscanf(&bufferLine[i], "%c",&ch);
		if(ch != ',')
		tempLine[j] = ch;
		lastch = ch;}
	for( j = 0,lastch = NULL; lastch != ','; j++, i++)
	            {sscanf(&bufferLine[i], "%c",&ch);
		if(ch != ',')
	tempLine[j] = ch;
		lastch = ch;}
	for( j = 0,lastch = NULL; lastch != ','; j++, i++)
		{sscanf(&bufferLine[i], "%c",&ch);
		if(ch != ',')
		tempLine[j] = ch;
		lastch = ch;}
				
			}
		}

		tempLine[j-i] = '\0';

		strcpy(item.partId, tempLine);

	fwrite (&item, sizeof(struct invent),1, outPut);

	fseek (outPut,0L, SEEK_SET);
	
	fread (&item, sizeof(struct invent,1, inPut);
		while(!feof(outPut))
			offset = ftell(outPut);

		printf("get character\n");

		getch;
	return 0;
}
  #2  
Old 20-Apr-2004, 23:18
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,281
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Please read the formatting tutorial, concentrate on the 2nd post in the thread on indentation.

Then edit your post so we can follow the program flow.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #3  
Old 20-Apr-2004, 23:58
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Thank you! I was just about to post to mention this and I scrolled down and saw that you beat me to it. Amir, you must definitely learn to format your code effectively. The stuff up there is as good as gibberish to my lazy eyes. Also, please give a more formal description of the assignment so that we know what it's supposed to do before we dive into the code.
__________________
-Aaron
  #4  
Old 21-Apr-2004, 11:58
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi Amir.

I am ussually not as vocal about exact formatting, but I think if you go through and simply reformat this code, it will make better sense.

For example, you have:
CPP / C++ / C Code:

struct date{
	int month, day, year;}reordDate;
	struct date blankDate = {0,0,0};


Which took me a minute to figure out what was going on. However, with something like:

CPP / C++ / C Code:
struct date{
  int month;
  int day; 
  int year;
}reordDate;

struct date blankDate = {0,0,0};

It makes it so much easier to understand what is going on. You may be able to answer your own questions easier by doing this as well

Cheers,
d
  #5  
Old 21-Apr-2004, 23:21
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Yeah, DSmith, reformating code to make it readable is one of the most important thing each programmer should have, but considering this, I have seen most guys don't care for it as long as the program do the job. Even my work looks messy sometimes, but I would take My time in the end to make my program reformated..

There should be a special class in schools for this.. heck, I would prefer a guy hired just to reformate the code we wrote and put comments, makes more readable... I should suggest this to my boss, but not sure what kind of response i would get...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #6  
Old 21-Apr-2004, 23:46
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Be a man... do it while you write the code :-P It's not that difficult, honestly!
__________________
-Aaron
  #7  
Old 22-Apr-2004, 03:01
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,281
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Max Payne
Yeah, DSmith, reformating code to make it readable is one of the most important thing each programmer should have, but considering this, I have seen most guys don't care for it as long as the program do the job.
This is simply not true. I've been a programmer for over 20 years and NO professional writes unformatted code. The moment a { gets on the page indenting begins. Period. If I wrote code without formatting until I get it working
1) it would take me extra time at the end to do the formatting, increasing the programming time. During development formatting takes no longer than nonformatting.
2) I'd get lost and have to waste time trying to figure out why this loop doesn't work and why that IF is broken.
Formatting helps in development. It's not just a nice thing to do.

Quote:
Originally Posted by Max Payne
Even my work looks messy sometimes, but I would take My time in the end to make my program reformated..
Be prepared when you get into the workforce them. You will have a tough time, esp when you ask someone for help, like here.

Quote:
Originally Posted by Max Payne
There should be a special class in schools for this.. heck, I would prefer a guy hired just to reformate the code we wrote and put comments, makes more readable... I should suggest this to my boss, but not sure what kind of response i would get...
Oh, you are working, eh? Then you've probably never worked on a team or a huge project. And hiring someone to do what the programming team is too lazy and arrogant to do is asinine. Your boss should fire the first one that suggests it.

There are classes for this. It's called "a programming class" and if the instructor isn't teaching you how to format code, he should be tarred and feathered, and strung up by his tenure. Not teaching formatting is like teaching driver's ed and ignoring what the mirrors are for. Heck, who needs to know where they've been
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
  #8  
Old 22-Apr-2004, 03:32
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Quote:
Originally Posted by WaltP
There are classes for this. It's called "a programming class" and if the instructor isn't teaching you how to format code, he should be tarred and feathered, and strung up by his tenure.
Absolutely, yes! I played a game awhile back called Jagged Alliance 2 that had a funny personality test, and one of the possible multiple choice answers to decide the fate of a certain purple dinosaur was, "...should be shot, hung from a tree, and run over by a buick." This is a deserving fate for any programmer I work with that does NOT format their code in a manner that is easy to read and understand!
__________________
-Aaron
  #9  
Old 22-Apr-2004, 04:44
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
Quote:
Originally Posted by WaltP
This is simply not true. I've been a programmer for over 20 years and NO professional writes unformatted code. The moment a { gets on the page indenting begins. Period. If I wrote code without formatting until I get it working
1) it would take me extra time at the end to do the formatting, increasing the programming time. During development formatting takes no longer than nonformatting.
2) I'd get lost and have to waste time trying to figure out why this loop doesn't work and why that IF is broken.
Formatting helps in development. It's not just a nice thing to do.
I'm not talking about professionals, I'm talking about my fellow friends at college. once we worked in a group of four for an assignement, and when the times come to testing the programs, it would be a sleepless nights checking for errorss... its all their fault because of their super messy code(mine just messy, not super mess)... not a single comment..

Quote:
Originally Posted by WaltP
Oh, you are working, eh? Then you've probably never worked on a team or a huge project. And hiring someone to do what the programming team is too lazy and arrogant to do is asinine. Your boss should fire the first one that suggests it.
yep. I never worked on huge projects..not yet..I'm still a beginner. too lazy ??
no i'm not lazy... I just like to work in slow motion..
Quote:
Originally Posted by WaltP
There are classes for this. It's called "a programming class" and if the instructor isn't teaching you how to format code, he should be tarred and feathered, and strung up by his tenure. Not teaching formatting is like teaching driver's ed and ignoring what the mirrors are for. Heck, who needs to know where they've been

hmmmm....thats too cruel...
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #10  
Old 22-Apr-2004, 11:02
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,281
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Max Payne
I'm not talking about professionals, I'm talking about my fellow friends at college. once we worked in a group of four for an assignement, and when the times come to testing the programs, it would be a sleepless nights checking for errorss... its all their fault because of their super messy code(mine just messy, not super mess)... not a single comment..
In my experience the longer you stick with a bad habit even though you know the correct technique, the harder it is to correct yourself when that correct technique must be used. FORMAT NOW!!! Don't wait. Kill the bad habit now or it will dog you the rest of your career.


Quote:
Originally Posted by Max Payne
hmmmm....thats too cruel...
Sorry, truth hurts.

I'd rather you start now being a good programmer than fighting your way thru later. You'll have enough to worry about when you really enter the workforce and learning these basics will in fact help you land the job. I'm not trying to be cruel, I'm trying to give you an edge over the other 250,000 graduates looking for the same job when the time comes.

You instuctor is not a professional programmer. He's a teacher. He probably doesn't know the importance of formatting code if he's not requiring you to do so. Whereas I am a professional programmer -- and I'm expensive -- and you'll just replace me 'cuz you're cheaper.... Fergit it -- don't format. I don't need the competition! ;-)
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
 
 

Recent GIDBlogToyota - 2008 November Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB 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
[Tutorial] GUI programming with FLTK dsmith FLTK Forum 10 03-Oct-2005 16:41
Project 2 BobbyDouglas C++ Forum 1 09-Sep-2003 22:02
Anyone need a PHP project done? geedubya15 New Member Introductions 2 25-Jun-2003 12:29
Grub's distributed web crawling project Good for webmasters running servers jrobbio Search Engine Optimization Forum 4 25-Jun-2003 09:48
GIDTopsites - my first PHP project! JdS GIDTopsites™ 14 15-Jul-2002 05:20

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:39.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.