Help Me 'sort' This Out

This is a discussion on Help Me 'sort' This Out within the C Programming forums, part of the General Programming Boards category; Code: struct tuple { char make[50]; char model[50]; char size[50]; char year[50]; char plate[30]; }; void sort(struct tuple * aDB) ...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    3

    Help Me 'sort' This Out

    Code:
    	struct tuple
    {
    	char make[50];
    	char model[50];
    	char size[50];
    	char year[50];
    	char plate[30];
    };
    
    
    void sort(struct tuple * aDB)
    {
    	int j;
    
    	FILE *myDB;
    	system("cls");
    	myDB = fopen ("cardata.csv", "r");
    	char sortdata[MAX*5];
    
    
    		for(j=0;j<MAX;j++)
    		{
    		char sortdata[(j*5)+0] = aDB->make;
    		char sortdata[(j*5)+1] = aDB->model;
    		char sortdata[(j*5)+2] = aDB->size;
    		char sortdata[(j*5)+3] = aDB->year;
    		char sortdata[(j*5)+4] = aDB->plate;
    		aDB++
    		}
    
    
    		{
    
    	fclose (myDB);
    
    	for (int k=0;k<MAX;k++)
    
    		{
    			printf("%s", sortdata[k]);
    		}
    
    	getch();
    	main();
    
    
    }
    Can you please take a look and help me solve this, im trying to sort these so that the program looking into my file, reads whats in there so that it can compare to the next entry and compare a field with that.

    i kno i have not put in the swap method but im trying to solve this so that i can move to the next stage.

    thank you for your time

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So what exactly is the problem? Other than...
    1 - calling main
    2 - not actually reading anything from your file
    3 - probably not having a C99 compiler, and mixing your declarations and funcion calls
    4 - declaring a ton of variables all called the same thing
    5 - etc etc etc

    You know, if you actually try to compile something, it (the compiler) will give you niftly little messages telling you where to start looking at problems.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    Don't mind Quzah's lists, he used to work for David Letterman.

    He was about right on with what he said though... unlike David Letterman and his lists.
    ...oh why did he fire Quzah.
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    3
    the problem lies, when i try to coompile this code with my work.

    it asks for a bracket '{' in the first line. but ibviously i cannot do this as the line has not finished.

    can someone direct where i need to start changing it about, its a simple mistake but not for me lol.

    please reply soon.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    3
    by the way, becasue this is a piece of code, that is why it dont have main.

  6. #6
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    so which line is that does that ask you for an '{'. i dnt really find any missing {. put i found one this

    Code:
    {
    
    	fclose (myDB);
    
    	for (int k=0;k<MAX;k++)
    
    		{
    			printf("%s", sortdata[k]);
    		}
    
    	getch();
    	main();
    what are trying to do here. this is a incomplete code. in theabove code u have one open braces and u dont close it any where. and i guess u are using main(); at end to return back to the main fucntion where the fucntion was called dont use main(); use return keywork which takes back u to the main fucntion.

    ssharish2005

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    He didn't say post main, he said call main.

    Code:
    main();   // don't do this
    Sent from my iPadŽ

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > myDB = fopen ("cardata.csv", "r");
    How about starting with three functions
    1. reads the file, and stores it in an array of struct tuple
    2. sorts the array
    3. prints the array - use this to check the reading and the sorting.

    Eg, in this order
    read
    print
    sort
    print

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  2. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  3. Sorting
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-10-2003, 04:21 PM
  4. radix sort and radix exchange sort.
    By whatman in forum C Programming
    Replies: 1
    Last Post: 07-31-2003, 12:24 PM
  5. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 07:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21