Return Entire Thread First 100 Posts Prev 100 Next 100 Last 50 Posts Report Thread Style: Yotsuba, Pseud0ch, Terminal

Pages: 1-

C process died on signal 10

1

will someone please explain to me why this is happenning.

compiles fine, when i run it though, i get this:

 ----jGRASP exec: /Users/mynamehere/Documents/CSC/a.out

 ----jGRASP wedge: process died on signal 10.
 ----jGRASP: operation complete.

heres the actual code, i've combed through it plenty times, and i still can't figure out this error. im using jGrasp, which is what was given to us by our professor, on mac os x 10.4
i've checked and verified the text file myself, and it's perfectly fine. i've also compiled and ran it on our campus' UNIX system using gcc -Wall -ansi -pedantic, but that returns "Segmentation fault (core dumped)"


/*
 *    my name here
 *       CPE 101
 *      Program 8
 */
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
typedef struct
   {
      char name[15];
      int aFieldGoals, fieldGoals,
          aFreeThrows, freeThrows;
   } playerData;

int totalPoints(playerData player);
double fieldGoalPercent(playerData player);
double freeThrowPercent(playerData player);
double teamFieldGoalPercent(const playerData players[]);
double teamFreeThrowPercent(const playerData players[]);
void displayPlayer(playerData player);
void displayPlayerArray(const playerData player[]);


int main()
{
   FILE *inp;
   playerData players[1000];
   char * name;
   int count = 1;
   int inputStatus;
   int errors = 0;
   int i;
   int aFieldGoals;
   int fieldGoals;
   int aFreeThrows;
   int freeThrows;
  
   inp = fopen("bbstats.txt", "r");
  
   if(inp == NULL)
   {
      printf("error, could not read file");
      exit(1);
   }
  
   inputStatus = fscanf(inp, "%s %d %d %d %d", name,
                 &aFieldGoals, &fieldGoals,
                 &aFreeThrows, &freeThrows);
                
   if((aFieldGoals >= 0) && (aFieldGoals <= 100) &&
      (fieldGoals >= 0) && (fieldGoals <= 100) &&
      (aFreeThrows >= 0) && (aFreeThrows <= 100) &&
      (freeThrows >= 0) && (freeThrows <= 100) &&
      (aFieldGoals >= fieldGoals) && (aFreeThrows >= freeThrows))
   {
  
      strcpy(name, players[count].name);
      players[count].aFieldGoals = aFieldGoals;
      players[count].fieldGoals = fieldGoals;
      players[count].aFreeThrows = aFreeThrows;
      players[count].freeThrows = freeThrows;
   }
   else
   {
      errors++;
      count--;
      printf("Invalid data in line %d", (count + errors));
   }
     
        
   while(inputStatus != EOF)
   {
      count++;
  
      inputStatus = fscanf(inp, "%s %d %d %d %d", name,
                 &aFieldGoals, &fieldGoals,
                 &aFreeThrows, &freeThrows);
                
      if((aFieldGoals >= 0) && (aFieldGoals <= 100) &&
         (fieldGoals >= 0) && (fieldGoals <= 100) &&
         (aFreeThrows >= 0) && (aFreeThrows <= 100) &&
         (freeThrows >= 0) && (freeThrows <= 100) &&
         (aFieldGoals >= fieldGoals) && (aFreeThrows >= freeThrows))
      {
         for(i = 1; i < count; i++)
         {
            if(strcmp(players[i].name, name) == 0)
            {
               players[i].aFieldGoals += aFieldGoals;
               players[i].fieldGoals += fieldGoals;
               players[i].aFreeThrows += aFreeThrows;
               players[i].freeThrows += freeThrows;
               errors++;
               count--;
            }
            else
            {
               strcpy(name, players[count].name);
               players[count].aFieldGoals = aFieldGoals;
               players[count].fieldGoals = fieldGoals;
               players[count].aFreeThrows = aFreeThrows;
               players[count].freeThrows = freeThrows;
            }
         }
      }
      else
      {
         errors++;
         count--;
         printf("Invalid data in line %d", (count + errors));
      }    
   }
   players[0].aFieldGoals = count;
   /*used to store the length of the array*/
   displayPlayerArray(players);
  
   fclose(inp);
   return 0;
}

int totalPoints(playerData player)
{
   return (player.fieldGoals * 2) + player.freeThrows;
}

double fieldGoalPercent(playerData player)
{
   return (double)player.fieldGoals / (double)player.aFieldGoals;
}

double freeThrowPercent(playerData player)
{
   return (double)player.freeThrows / (double) player.aFreeThrows;
}

double teamFieldGoalPercent(const playerData players[])
{
   int aTotal = 0, total = 0, i;
  
   for(i = 1; i <= players[0].aFieldGoals; i++)
   {
      aTotal += players[i].aFieldGoals;
      total += players[i].fieldGoals;
   }
  
   return (double)total / (double)aTotal;
}

double teamFreeThrowPercent(const playerData players[])
{
   int aTotal = 0, total = 0, i;
  
   for(i = 1; i <= players[0].aFieldGoals; i++)
   {
      aTotal += players[i].aFreeThrows;
      total += players[i].freeThrows;
   }
  
   return (double)total / (double)aTotal;
}

void displayPlayer(playerData player)
{
   printf("%s\t\t\t", player.name);
   printf("%d\t", player.aFieldGoals);
   printf("%d.\t", player.fieldGoals);
   printf("%.2f\t", fieldGoalPercent(player));
   printf("\t%d\t", player.aFreeThrows);
   printf("%d\t", player.freeThrows);
   printf("%.2f\t", freeThrowPercent(player));
   printf("\t%d", totalPoints(player));
}


void displayPlayerArray(const playerData player[])
{
   int i;
  
   for(i = 1; i <= player[0].aFieldGoals; i++)
   {
      printf("Player\t\t\tTried\tmade\tp\t\ttried\tmade\tp\t\tpoints\n");
      displayPlayer(player[i]);
   }
  
   printf("\t\t\tTeam Avg %.2f\t\tTeam Avg %.2f",
          teamFieldGoalPercent(player),
          teamFreeThrowPercent(player));
}

2

Your char* name doesn't point to a buffer when fscanf uses it. Remember, fscanf doesn't malloc any space for strings - you need to do this yourself beforehand.

3

oh my god you saved my life.
thank you so much.

we haven't learned that in class, and it isn't mentioned anywhere in the text. my program now works.

thank you again.

4

I don't know about any other compilers, but Microsoft's Visual C++  compiler would've reported a warning of "uninitialized local variable 'name' used" for this particular class of error.

5

you suck, rewrite it in c++

6

----jGRASP wedge: process died on signal 10.
good night, sweet prince

7

>>5

Don't be stupid, it was obviously for a C assignment you cocksmoker.

8

hey guys help me do my homework lol

9

>>7
and you would obey your stupid teacher like the crybaby you are? I wouldn't.

10

>>9
Enjoy your F for FAIL.

11

>>10
lol no loser

12

>>11

You're an idiot.

13

>>12
lol pwned for answering==============

14

>>13

No

15

>>14
agaiiiiiiiiiiiiiiiiiiiiiiiin, you're a winner!

16

Why reinvent the wheel?

17

Was VIP quality That   was VIP quality   That was VIP   quality That was   VIP quality That   was VIP quality   That was VIP   quality That was   VIP quality That   was VIP quality   That was VIP   quality That was   VIP quality That   was VIP quality   That was VIP   quality That was   seriously fucked up   than it originally   would have And   you will see.

18


like it broke again?

21

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy


Newer Posts

Name: Email:
22
Entire Thread Last 50 Posts First 100 Posts Thread List Report Thread