Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C process died on signal 10

Name: Anonymous 2006-11-21 5:01

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));
}

Name: Anonymous 2006-11-21 6:19

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.

Name: Anonymous 2006-11-21 7:05

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.

Name: Anonymous 2006-11-21 17:18

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.

Name: Anonymous 2006-11-22 13:48

you suck, rewrite it in c++

Name: Anonymous 2006-11-22 14:16

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

Name: Anonymous 2006-11-23 4:56

>>5

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

Name: Anonymous 2006-11-23 5:15 (sage)

hey guys help me do my homework lol

Name: Anonymous 2006-11-23 13:42

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

Name: Anonymous 2006-11-24 6:12

>>9
Enjoy your F for FAIL.

Name: Anonymous 2006-11-24 14:31

>>10
lol no loser

Name: Anonymous 2006-11-24 14:33

>>11

You're an idiot.

Name: Anonymous 2006-11-24 14:49

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

Name: Anonymous 2006-11-24 15:30

>>13

No

Name: Anonymous 2006-11-25 9:56

>>14
agaiiiiiiiiiiiiiiiiiiiiiiiin, you're a winner!

Name: Anonymous 2009-01-14 14:12

Why reinvent the wheel?

Name: Anonymous 2009-02-25 7:56

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.

Name: Anonymous 2009-03-06 5:55


like it broke again?

Name: Sgt.Kabu序敹kiman䳪앥 2012-05-28 20:53

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
Don't change these.
Name: Email:
Entire Thread Thread List