Thread: Why does this not work :-p ?

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    18

    Talking Why does this not work :-p ?

    #include <stdio.h>
    #include <math.h>

    void datain(int,int,float[10000][4]);
    void prtable(int,int,float[10000][4]);
    void sortdata(int,int,float[10000][4]);
    void main ()
    {
    /*Author:GSD
    Date:09.11.2001
    Assignment 2:
    Modifications: None
    Version 1.0*/

    int n,m;
    float a[10000][4];
    a[0][0]=0.0;
    n=4;
    printf("Please enter the number of persons in the table\n\r");
    scanf("%d",&m);
    /*Create table and input data*/
    datain(n,m,a);
    /*print out the table unsorted*/
    prtable(n,m,a);
    /*sort date
    sortdata(n,m,a)*/
    }


    void datain(int n,int m,float a[10000][4])
    {
    /*Author: GSD
    Date:09.11.2001
    Assignment 2:
    Modifications: None
    Version 1.0
    Function: Fixing the size of the two dimensional array and input the data*/

    int i,j;
    for (j=1;j<=n;j++)
    {
    for (i=1;i<=m;i++)
    {
    if (j==1) printf("\n\rPlease enter Person Id of person %3d ",i);
    if (j==2) printf("\n\rPlease enter the value of wage of person %3d ",i);
    if (j==3) printf("\n\rPlease enter the sex ((0) male (1) female) of person %3d ",i);
    if (j==4) printf("\n\rPlease enter the age of person %3d ",i);
    scanf("%f",&a[i][j]);
    }
    }
    return;
    }

    void prtable(int n,int m,float a[10000][4])
    {
    /*Author: GSD
    Date:09.11.2001
    Assignment 2:
    Modifications: None
    Version 1.0
    Function: To print out the data unsorted*/


    int i,j;
    printf(" Person ID\tWage\t Sex\t Age\n\r");
    for (i=1;i<=m;i++)
    {
    for (j=1;j<=n;j++)
    {
    printf("%10.0f",a[i][j]);
    }

    printf("\n\r");
    }
    return;
    }

    void sortdata(int n,int m,float a[10000][4])
    {
    /*Author: GSD
    Date:09.11.2001
    Assignment 2:
    Modifications: None
    Version 1.0
    Function:To sort the data*/

    int i,j,t;
    char type;
    t=1;
    while (t==1)
    {
    printf("\n\rHow do you want the data to be sorted ?");
    printf("\n\rAscending by Person ID,type a");
    printf("\n\rAscending by Wage, type b");
    printf("\n\rAscending by Age, type c");
    printf("\n\rOnly females, print d");
    printf("\n\rOnly males, print e\n\r");
    scanf("\n%c",&type);
    if (type='a')
    {
    printf("Person ID\tWage\tSex\tAge");
    printf("%10.0f",a[i][j]);
    }
    else
    {
    printf("\n\rNot yet working");
    }
    printf("Do you want to sort the array again? Yes (1) or No (0)");
    scanf("%d",&t);
    }
    return;
    }


    The sort function does not work any clues

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    18

    Talking

    no errors or warnings are given in visual studio . the program simply terminates after the printtable function !!!!

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    your sort function only does a print. there is no sorting implemented there.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > void main ()
    Use int main

    And don't forget to add a
    &nbsp; return 0;
    to the end of main

    > float a[10000][4];
    Any idea how big this is, and how much stack space this takes?
    160K by my estimation

    This is one of those rare examples where a global variable might be better - but if your compiler/OS is happy with it, then leave it alone.

    > for (j=1;j<=n;j++)
    here's the big problem - arrays start at 0, not 1
    The correct way to access an array is
    &nbsp; for (j=0;j<n;j++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM