1 Replies - 3264 Views - Last Post: 11 October 2015 - 10:21 PM Rate Topic: -----

#1 alexz003  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 78
  • Joined: 08-May 10

A mistake I made trying to show off

Posted 11 October 2015 - 09:57 PM

So in my first semester at University, my Intro to C class had this catch where, if you did a tough(?) assignment within the first 10 days, he would give you an A and you could skip the rest of the course. Since I came from an advanced java and c# background, I took on the assignment.

I was basically trying to prove to my professor that I knew my shit, and literally incorporated as many concepts that I could be expected to learn in that class, into my assignment. In that heap of mess, I found this hunk of gold:

void readDataFile(Tickets *tickets, Auction *auction, Raffle *raffle, Drinks *drinks)
	char filePath[100];

	int eventCount;
	//Get input
	printf("Please enter the name of the text file: ");
	scanf("%s", filePath);

	FILE *in = fopen(filePath, "r");

	if (in != NULL)
		char buffer[BUFFER_SIZE];

		//First 8 lines of file are input data
		int x = 0;
		for (x = 0; x < 8; x++) 
			if (fgets(buffer, BUFFER_SIZE, in) != NULL)
				switch (x) 
				case 0: //Initializes Ticket data
					setTicketData(tickets, buffer);
				case 1: //Initializes Auction data
					setAuctionData(auction, buffer);
				case 2: //Allocates memory and sets Auction data
					setAuctionItems(auction, buffer);
				case 3: //Initializes Raffle data
					setRaffleData(raffle, buffer);
				case 4: //Allocates memory and sets Raffle data
					setRaffleItems(raffle, buffer);
				case 5: //Sets Drink data
					setDrinkStock(drinks, buffer);
				case 6: //Sets Drink prices
					setDrinkPrices(drinks, buffer);
				case 7: //Set number of event actions
					eventCount = setEventCount(buffer);
					int y = 0;
					for (y = 0; y < eventCount; y++)
						if (fgets(buffer, BUFFER_SIZE, in) != NULL)
							performEvent(buffer, tickets, auction, raffle, drinks);

		printf("File does not exist");

And so, this was the feedback I received:


Very clean, easy to read code. Output ran perfectly with no errors. Good documentation and use of whitespace as well.

Side note: VERY VERY VERY BAD USE OF SWTICH. Never use it again. It's redundant and looks disgusting. I almost failed you for this alone, but my opinion shouldn't determine your success. Come to my office so I can tear it apart for you >:]

Just thought I would post this since I found it funny going back through my old assignments.

Is This A Good Question/Topic? 0
  • +

Replies To: A mistake I made trying to show off

#2 jon.kiparsky  Icon User is offline

  • Chinga la migra
  • member icon

Reputation: 10787
  • View blog
  • Posts: 18,445
  • Joined: 19-March 11

Re: A mistake I made trying to show off

Posted 11 October 2015 - 10:21 PM

Oh, wow. That's really awful. I feel a little unwell now.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1