LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-01-2006, 08:25 AM   #1
stuckatc
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
Please help me with small college program


hello all, newbie here and with C, weve been asked to impklement this program below, basically its a shell sort which sorts a football table into points then on goal difference

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

#define MAX 25

struct team{
char Team[MAX];
int Played;
long Points;
int Goalsfor;
int Goalsagainst;
};

void read_file(struct team league[]);
void ShellSort(struct team league[], int n);
void printdetails(struct team league[]);

/* read in file*/

int main()
{
struct team league[8];
int n;
int eofind;
n = 8;
read_file(league);
ShellSort(league, n);
printdetails(league);

}


void read_file(struct team league[])
{
int eofind;
FILE *leugue_pointer;
int x;
x=0;
eofind=0;
leugue_pointer = fopen("leuguedetails.text", "r");

eofind = fscanf(leugue_pointer, "%s", league[x].Team);
eofind = fscanf(leugue_pointer, "%d", &league[x].Played);
eofind = fscanf(leugue_pointer, "%d", &league[x].Points);
eofind = fscanf(leugue_pointer, "%d", &league[x].Goalsfor);
eofind = fscanf(leugue_pointer, "%d", &league[x].Goalsagainst);

while (eofind != EOF)
{
x++;
eofind = fscanf(leugue_pointer, "%s", league[x].Team);
eofind = fscanf(leugue_pointer, "%d", &league[x].Played);
eofind = fscanf(leugue_pointer, "%d", &league[x].Points);
eofind = fscanf(leugue_pointer, "%d", &league[x].Goalsfor);
eofind = fscanf(leugue_pointer, "%d", &league[x].Goalsagainst);
}

fclose(leugue_pointer);
}

void ShellSort(struct team league[], int n)
{
int i, j, k, s, gap_cnt ;
i = 0;
j = 0;
gap_cnt = 0;
k = 0;



char temp;

int temp0;
char temp1[MAX];
int temp2;
int temp3;
int temp4;



for (gap_cnt = 0; gap_cnt < 8; gap_cnt++)








{

strcpy(temp1, league[k].Team);
temp2 = league[k].Played;
temp0 = league[k].Points;
temp3 = league[k].Goalsfor;
temp4 = league[k].Goalsagainst;

s = -k;

for (i = k; i < n; ++i)


{
strcpy(temp1, league[i].Team);
temp2 = league[i].Played;
temp0 = league[i].Points;
temp3 = league[i].Goalsfor;
temp4 = league[i].Goalsagainst;

j = i-k;

if (s == 0)


{
s = -k;

s++;

strcpy(league[i].Team, temp1);
league[i].Played = temp2;
league[i].Points = temp0;
league[i].Goalsfor = temp3;
league[i].Goalsagainst = temp4;
}


while ((temp <= league[j]) && (j >= 0) && (j <= n));


{


strcpy(league[j+k].Team, temp1) = strcpy(league[j].Team, temp1);
league[j+k].Played = league[j].Played;
league[j+k].Points = league[j].Points;
league[j+k].Goalsfor = league[j].Goalsfor;
league[j+k].Goalsagainst = league[j].Goalsagainst;

j = j-k;

}



strcpy(league[j+k].Team, temp1);
league[j+k].Played = temp2;
league[j+k].Points = temp0;
league[j+k].Goalsfor = temp3;
league[j+k].Goalsagainst = temp4;
}


}



void printdetails(struct team league[])
{
int x;
x = 0;

printf("Team\t\tPlayed\tPoints\tGoals for\tGoals against""\n");
for (x = 1; x < 8; x++)
{

printf("%s\t%d\t%d\t%d\t\t%d\n", league[x].Team,league[x].Played,league[x].Points,league[x].Goalsfor,league[x].Goalsagainst,"\n");


}
}


and im getting these error messages

assesment2.c: In function `ShellSort':
assesment2.c:129: error: invalid operands to binary <=
assesment2.c:135: error: invalid lvalue in assignment
assesment2.c:172: error: parse error at end of input

if anyone can help me with this i would be forever in their debt...

i can post the file that is being read in if needed as well.
 
Old 06-01-2006, 08:55 AM   #2
titanium_geek
Senior Member
 
Registered: May 2002
Location: Horsham Australia
Distribution: elementary os 5.1
Posts: 2,479

Rep: Reputation: 50
Welcome to LQ!

try editing your post and placing [ code] [ /code] tags around the code? (remove the first space in those tags. They are written like that so they will render correctly to show you.)

also- this looks suspiciously like homework...
http://www.linuxquestions.org/rules.php

titanium_geek
 
Old 06-01-2006, 12:37 PM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I don't think this thread really violates any LQ rules, because it's not as if stuckatc is asking for us to write a program that does what they need. He/she at least has made an attempt to do it and just needs some help. Sounds fair to me.

Code:
while ((temp <= league[j]) && (j >= 0) && (j <= n));
One thing is that there shouldn't be a semi-colon at the end of that line. I'm not too sure what else is wrong with that line, especially since I don't really know about structs. It could be something to do with you using league[j], but I'm not sure.

Also, please at least highlight the other lines where the errors occur.
 
Old 06-01-2006, 01:27 PM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
It's quite simple: "<=" doesn't work for structs. What I would do if I were you is to write a functions which compares two teams--much like strcmp. It would probably also be `nicer' if you wrote a generic shell-sort (see qsort), but no pressure from me there.

Also, since none of the data in your struct team is a pointer, you can say something like this:
Code:
struct team a = new_team(), b = new_team(), tmp;
tmp = a; a = b; b = tmp;
(you can use "=" for struct no matter what they contain, only sometimes it might not do The Right Thing).

Finally, parse errors at end of file is usually a missing brace somewhere. If you use emacs, try making it reindent your file, and see if anything looks odd.
 
Old 06-02-2006, 07:13 AM   #5
stuckatc
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
thanks for the help with that!!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with small program batalia Linux - Newbie 8 11-07-2005 02:41 PM
Compile a small program Dauer Ubuntu 2 11-05-2005 04:17 AM
I'm a student at a small midwestern college. gulo LinuxQuestions.org Member Success Stories 4 02-06-2005 01:11 PM
How can you reverse engineer a small C program OrganicX Programming 1 01-30-2004 08:30 PM
A small program to stop iptables satimis Linux - Newbie 6 09-15-2003 12:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration