Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


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

Rep: Reputation: 0
please help with small sort program

hello all, newbie here and with C, i have been been asked to implement 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;
ShellSort(league, n);


void read_file(struct team league[])
int eofind;
FILE *leugue_pointer;
int x;
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)
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);


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;


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, 01:17 PM   #2
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911Reputation: 911
Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Please help me with small college program stuckatc Linux - Software 4 06-02-2006 07:13 AM
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
How can you reverse engineer a small C program OrganicX Programming 1 01-30-2004 08:30 PM
Asking anyone who will make a small program for free. weblion Programming 7 12-02-2001 09:49 PM > Forums > Linux Forums > Linux - Newbie

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

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