C program help

Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
edited February 2005 in Internet & Media
(line)

(87) #define maxStudents 45
(88) #define maxColumns 10
(89) #define maxDataPoints 271
(90)
(91) void welcome  (void);
(92) void farewell (void);
(93) int getData (int aryStudentData [][maxColumns], int maxDataPoints);
(94) int doCalc (int aryStudentData [][maxColumns]);
(95) int printData (int aryStudentData [][maxColumns]);

Those are the lines that are relevant; everything above line 87 is comments, except for the include < stdio.h > line. I can post the rest of the source if necessary, but I don't think it is.

The program isn't done, but I'm trying to debug it as I go. Here are the errors Visual C++.NET is giving me. I can't seem to make it happy, and it's driving me nuts.
\Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2143: syntax error : missing ')' before 'constant'
\Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2143: syntax error : missing '{' before 'constant'
\Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2059: syntax error : '<Unknown>'
\Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(93) : error C2059: syntax error : ')'

Help, please!! :bawling:

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited February 2004
    is it possible your problem is here...i dont know C, just JAVA, but you've already defined maxDataPoints as 271 above, and here you're using it as a parameter...
    (93) int getData (int aryStudentData [][maxColumns], [b]int maxDataPoints[/b]);
    
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    I agree.

    Also, though, after you do that I'd like to know if it works (not just compiles).

    I think you might be given some problems because of aryStudentDate[][maxColumns]

    I would just use:
    int getData (int aryStudentData[][], int maxDataPoints);
    int doCalc (int aryStudentData[][]);
    int printData (int aryStudentData[][]);
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    Hmm. I've always used the actual variable name in the prototype declaration without a problem. Of course, maxDataPoints is a constant, not a variable, so that may explain it.

    replacing maxDataPoints with a random name (I just used int a, actually) took care of it. Thanks. :)

    A2J, I tried removing the maxColumns, but the compiler had a fit, and (according to my instructor, anyhow) the second value in a 2d array (the number of columns) has to be defined. So... now I just have to finish writing it and figure out why it thinks aryStudentData is an undeclared identifier... ;D
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    What is the actual assignment?

    If you're getting more compiler errors then post more source for us to look at and the exact messages. Is your instructor a "I don't wany any warnings" type of guy? Mine was. I am now, too. Warnings may not be errors, but they might lead to them in the future if not immediately. Best to fix all warnings.
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    Here's the assignment, from the source file:
    /********************************************************************************
    ** CIS 15 BG-03
    ** Winter, 2004
    ***************
    **
    ** Lab 3     Two-Dimensional Arrays        20 Points
    **
    ****************************************************
    
      Reading Assignment: Page 402, Programming Example - Calculate Averages
    
      Write a program to keep records and perform statistical analysis for a 
      class of students. The class may have up to 45 students 
      (validation required: see Line 70, page 368). 
      
      There are five quizzes during the quarter. Each student is identified 
      by a personal identification number (PIN) of four digits.
    
      Input : Read data from a text file. The text file has the following format:
        
            3
    
            1110    78    55    80   100    86
            1111    67    78    45    89    35
            1112    23    66    78    79    90
    
      3 - represents the number of students in the class;
      1110 - represents the Personal Identification Number of a student; it is 
      followed by 5 integers representing the quiz scores.
    
      Output: Write the output to another text file (see the example below).  
    	      The output is to contain:
    
          1. Students' statistics (lowest score, largest score, sum, and average)
                  
          2. Quizzes' statistics (lowest score, largest score, sum, and average).
                  
          3. Class average. 
    
    
      Data: Run your program once, using SCORES.TXT
    
      Example: If the data file contains data for two students 
      the output should be:
    
      STUDENTS: Statistical Analysis
    
      PIN    Quiz1  Quiz2  Quiz3  Quiz4  Quiz5 | Low   High   Sum    Ave
      ====   =====  =====  =====  =====  ===== | ====  ====  ====  =====
      1019	    90	   80	  85	100	    60 |   60   100   415   83.0 
      1178	    82	   90	  90	 45	    89 |   45    90   396   79.2 
      ==================================================================
    
      QUIZZES: Statistical Analysis
    
      PIN	 Quiz1  Quiz2  Quiz3  Quiz4  Quiz5 
      ====   =====  =====  =====  =====  ===== 
      1019      90     80     85    100     60	 
      1178	    82	   90	  90     45	    89	 
            _______________________________________
    
      Low       82     80     85     45     60          
      High      90     90     90    100     89
      Sum      172    170    175    145    149
      Ave       86.0   85.0   87.5   72.5   74.5
      =======================================================
    
      CLASS AVERAGE: 81.10 
                      
    ****************************************
    **
    **  Written By:  ???
    **
    **  Date: 1/26/02 - ??/??/02  
    **
    ********************************************************************************/
    

    I'm not done with it at the moment, tho. I figured I'd finish it first, because the other errors could just be because the program isn't done, so there are some loose ends if you will. To answer your question, yes, my instructor is picky about that kind of stuff. You're right- warnings are going to cause problems later. Right now tho, there are no warnings. Just errors. :rolleyes:;D
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    Well, if you get stuck, post your questions.

    I have Jury Duty in the morning (how fun) so I doubt I'll be able to see any questions you might have before tomorrow afternoon, but I'm sure others can help if I'm not available.
  • edited February 2004
    I only know C++, but try throwing a const infront of the int, it looks like it wants you to define it as a constant in the function prototype. also sometimes I get errors like that in visual studio if I have copied from something outside of the program, that might be causing the problem too. in arrays bigger than 1 dimension, every value past the first one has to be defined.
  • TheBaronTheBaron Austin, TX
    edited February 2004
    you can never define local variables with the same name as a global variable, it creates a conflict when the compiler trys to decide which one you're trying to access
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    I'm not trying to be "nit-picky" here but you're actually wrong.
    The compiler doesn't have any problems with #define X 1 and int X = 1;

    The reason is the preprocessor actually replaces "X" in the code with "1" so the compiler will never see "X" it will see "1" and it's that which confuses the compiler.

    The compiler never saw "maxDataPoints" it only saw "271" and it wasn't expecting that.
    TheBaron wrote:
    you can never define local variables with the same name as a global variable, it creates a conflict when the compiler trys to decide which one you're trying to access
  • TheBaronTheBaron Austin, TX
    edited February 2004
    meh, you win
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    :hrm: I missed those last couple posts for some reason.

    Aaaaaaaaanywho, I figured it was easier to start over after I realized that there's a very similar program in the book. I simply scanned it and edited it a bit.

    I've got it almost finished. It's giving me two errors tho:

    Build started: Project: Lab3, Configuration: Debug Win32

    Compiling...
    BG_Lab_3.c
    \Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(164) : error C2692: 'exit' : fully prototyped functions required in C compiler with the '/clr' option
    \Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\BG_Lab_3.c(164) : error C2197: 'exit' : too many arguments for call through pointer-to-function

    Build log was saved at "file://c:\Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab3\Lab3\Debug\BuildLog.htm"
    Lab3 - 2 error(s), 0 warning(s)


    Done

    Build: 0 succeeded, 1 failed, 0 skipped


    I'll attach the source code and the build log, but I've never understood these "too many arguments for call through..." errors, and this particular code is straight out of the text, so I don't understand why it's blowing up.

    Regardless, there's the error, the code and the buildlog are zipped.
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    Slacker!
    Geeky1 wrote:
    :hrm: I missed those last couple posts for some reason.

    I'll look @ the code and see if I can find what the deal is.
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    Heh. Tnx.
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    I have no errors during compilation.

    Only error I get is when I run the program:
    C:\Documents and Settings\Administrator\Desktop\Lab3>bg_lab_3.exe
    LAB 3 - Two-Dimensional Arrays

    Error opening file



    I use Dev-C++. 4.9.8.0 and then I applied the 4.9.8.7 upgrade to the install directory. You can find it at http://www.bloodshed.net
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    Hmm. Weird. I'll try rebooting; VC++ is strange. The reason it gave you that error is because it needs an external file (scores.txt) to read the scores from :)
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    If rebooting doesn't work, try changing the value sent to exit(). Perhaps exit(-1) or so.
    Geeky1 wrote:
    Hmm. Weird. I'll try rebooting; VC++ is strange. The reason it gave you that error is because it needs an external file (scores.txt) to read the scores from :)
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    Hmm. I tried rebooting, it didn't work. Didn't see your post before I started "fixing" stuff... :D I just deleted that line and commented out some other stuff. It now compiles and runs without throwing a fit, but for some reason, the entire array is filled with the last value in the file.

    I put the scores.txt file, the updated source and the exe in another zip file (attached)... I also have to set it up so that the program recognizes the first entry in the text file as the number of students in the class. I think I have an idea of how to do it, but I'm not sure. I was going to put a fscanf line in front of the for loops in the getdata function, and set it = to a variable that the for loop uses to determine the number of rows in the array.
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    One of your problems is you're using MAX_ROWS and MAX_COLS everywhere, even though the number of students can change so the MAX_ROWS should only be used as a stop gap to say "don't go past this" not to say "always go up to this."

    Also, getData() has nested for()s which is fine, but your scanf() is outside the inner for() meaning the dataIn is never changed until the the for()s are completely done unrolling they start all over because of the while(), so only until the while() is reached again (after 46 * 6 iterations) is the dataIn variable assigned a new value.

    Also, you're not reading the first line as the # of students and you're not taking the first column as the student ID. I'm working on it, though, but I'm doing other studd too so it might be faster if you just fix it yourself. If you don't post that you've fixed it by the time I'm done then I'll post what I've changed and hopefully it will work for you.
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    1) My "fix" for getData() is rather crude, but it seems to work. You can polish it up later and reduce the code redundancy.
    2) I replaced almost all instances of MAX_COLS with (MAX_COLS - 1)

    Seems to be working.
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    Ok, thanks. It looks like I've got this...
    Also, getData() has nested for()s which is fine, but your scanf() is outside the inner for() meaning the dataIn is never changed until the the for()s are completely done unrolling they start all over because of the while(), so only until the while() is reached again (after 46 * 6 iterations) is the dataIn variable assigned a new value.
    ...fixed.

    I'm working on the other two right now. :)
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    Ok... I forgot. How do I get it to pass data using pointers? I've tried to make a variable "actualRows" that uses a pointer to pass its value back to main. I could have it return an int if I needed to, but I'd rather not. What do I use when I use scanf and printf? is it still "fscanf(fpData, "%d", &actualRows);" and "printf("%d", actualRows);" or what? I can't remember...
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    How the hell did you post something at 7:59 AFTER I posted something at 8? WTF? Either I've lost it, or the server's lost it, and I haven't lost it. Have I? ;D
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    Everything OK?
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited February 2004
    I'm plugging away. ;D How do I get it to pass data using pointers?
  • a2jfreaka2jfreak Houston, TX Member
    edited February 2004
    my getData() returns an int, which is the actual rows (though I call it totalStudents).

    But if you want to do it w/ pointers:

    int* actualRows;

    Then, you guessed it, pass "actualRows" =)
    Your arrays are really pointers. C/C++ doesn't have arrays, it only has array-notation. It's all pointers. You're already passing pointers, but you're doing it using array notation. Just change notation, or you could (never tried it before) pass an array of 1 int. eg:
    int actualRows[1];
    Then pass it like you already are. I don't know of any reason that it wouldn't work, though I have never tried a 1-dimensional 1-element array before that I can recall.
  • Geeky1Geeky1 University of the Pacific (Stockton, CA, USA)
    edited March 2004
    Thanks for the help! That program is done, and now I have one more to write (I was sick, so I'm catching up). It's not done, but I'm trying to get it to compile and run the way it is, so I don't have to fix it after I've finished it and I have to deal with debugging a much larger program.

    Anyhow, here's the program code (I'll also zip and attach it):
    /********************************************************************************
    ** CIS 15 BG-03
    ** Fall,   2003
    ***************
    **
    ** Lab 4        Pointer Applications    20 Points
    **
    *************************************************
    
      Write a program that reads the size of an array from the keyboard. 
      The array is to be dynamically allocated in the heap. 
      Then the program reads integers from the keyboard into the array. 
    
      Modify the straight insertion sort from Chapter 8 so that it sorts
      the array into ascending order. 
      
      The program must not change the original array and must not create a
      copy of it. (See figure 10-25, page 515).
    
      Print the sorted array and the original array to a file, using the 
      following format:
    
      ==========   ===========   ============   
       ORIGINAL     ASCENDING     DESCENDING
      ==========   ===========   ============   
          50           20            100
          70           50             70
          20           50             70
         100           70             70
          70           70             50
          50           70             50
          70          100             20
    
      
      Data		:  Run  your program  twice:
    
        Test Data Set 1:
    
        10     here you enter the size of the array  
        10 10 30 30 40 50 50 50 60 60
    
    
        Test Data Set 2:
    
        25
        50 30 10 90 5 20 25 90 40 35 50 30 50 30 90 5 40 50 90 30 10 5 20 10 35
    
      NOTE: Use pointer notation throughout. Do not use an index to access the 
      elements in the array: use a pointer, as in the following example:
      ____________________________________________________________________
      YES
    
      int ary[10] = {10, 15, 10, 30, 40, 50, 60, 70, 80, 90 };
    
      int *pWalk;
      int *pLast;
    
      pLast = ary + 10 - 1;
      for( pWalk = ary; pWalk <= pLast; pWalk++ )
         printf( "%3d", *pWalk );
    
      _____________________________________________________________________
      NO
    
      int ary[10] = {10, 15, 10, 30, 40, 50, 60, 70, 80, 90 };
    
      int i;
    
      for( i = 0; i < 10; i++ )
         printf( "%3d", *(ary + i) );
     
    ****************************************
    **
    **  Written By:  First_Name Last_Name ???
    **
    **  Date: 2/6/02 - ???
    **
    ********************************************************************************/
    
    #include < stdio.h >
    #include < stdlib.h >
    #include < crtdbg.h >
    
    #define maxSize 100
    /* Prototype Declarations */
    
    void welcome  (void);
    void farewell (void);
    void getData (int array [], int *arraySize);
    void sortArray (int array []);
    void printArray (int array [], int arraySize);
    int main (void)
    {
    /* Local Definitions */
    	int array [maxSize];
    	int arraySize;
    
    /* Statements */
       welcome ();
       getData (array [maxSize], &arraySize);
       printArray (array [maxSize], arraySize);
       
       printf( _CrtDumpMemoryLeaks() ? "Memory Leak\n" : "No Leak\n");
       farewell ( );
    
       return 0;
    
    } /* main */
    
    
    /* ============================== welcome ==============================
    	Prints a welcome message.
    	   PRE  : nothing
    	   POST : welcome message printed
    */
    void welcome (void)
    {
    /*  Local Definitions */
    
    /*  Statements */
    	printf("\t\t LAB 4 - Pointer Applications\n\n");
    	
    	return;
    
    } /* welcome */
    
    /* ============================== farewell ==============================
    	Prints a farewell message.
    	   PRE  : nothing.
    	   POST : farewell message printed
    */
    void farewell (void)
    {
    	printf("\n\t\tEnd of the program!"
    		   "\n\t\tHave a great day!\n");
    
    	return;
    
    } /* farewell */
    
    void getData (int array [], int *arraySize)
    {
    	int i;
    
    	printf("Array Size: ");
    	scanf("%d", &arraySize);
    	for (i = 0; i <= arraySize; i++);
    	{
    		printf("\nValue: ");
    		scanf("%d", &array[i]);
    	}
    	return;
    }
    
    void printArray (int array [], int arraySize)
    {
    	FILE *fparray;
    	int i;
    	
    	fparray = fopen("array.txt", "w");
    
    	fprintf ("fparray", "==========   ===========   ============\n");
    	fprintf ("fparray", " ORIGINAL     ASCENDING     DESCENDING\n");
    	fprintf ("fparray", "==========   ===========   ============\n");
    
    	for (i = 0; i <= arraySize; i++)
    	{
    		if (i %3 != 0)
    		{
    			fprintf("fparray", "%6d", array[i]);
    		}
    		else
    		{
    			fprintf("fparray", "\n");
    			fprintf("fparray", "%6d", array[i]);
    		}
    	}
    	scanf("%d", i);
    }
    
    void sortArray (int array [])
    {
    	return;
    }
    

    It compiles fine, (albiet with warnings, which you can see below), but when it gets to scanning numbers into the array, it crashes.

    Here are the warnings:

    Build started: Project: Lab4, Configuration: Debug Win32

    Compiling...
    Lab4.c
    Lab4.c(100) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int'
    Lab4.c(101) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int'
    Lab4.c(147) : warning C4047: '<=' : 'int' differs in levels of indirection from 'int *'
    Lab4.c(162) : warning C4133: 'function' : incompatible types - from 'char [8]' to 'FILE *'
    Lab4.c(163) : warning C4133: 'function' : incompatible types - from 'char [8]' to 'FILE *'
    Lab4.c(164) : warning C4133: 'function' : incompatible types - from 'char [8]' to 'FILE *'
    Lab4.c(170) : warning C4133: 'function' : incompatible types - from 'char [8]' to 'FILE *'
    Lab4.c(174) : warning C4133: 'function' : incompatible types - from 'char [8]' to 'FILE *'
    Lab4.c(175) : warning C4133: 'function' : incompatible types - from 'char [8]' to 'FILE *'
    c:\documents and settings\kevin\my documents\visual studio projects\lab4\lab4.c(100) : warning C4700: local variable 'array' used without having been initialized
    Linking...

    Build log was saved at "file://c:\Documents and Settings\Kevin\My Documents\Visual Studio Projects\Lab4\Debug\BuildLog.htm"
    Lab4 - 0 error(s), 10 warning(s)


    Done

    Build: 1 succeeded, 0 failed, 0 skipped
  • a2jfreaka2jfreak Houston, TX Member
    edited March 2004
    Well, first off, you're not using pointer notation. :)
    Better fix that. None that wimpy array[x] crap here! :D

    I'll try to remember to look @ the code before I go to sleep, but I'll probably be going to sleep in about an hour or so so don't hold your breath thinking I'll get it done tonight.
  • a2jfreaka2jfreak Houston, TX Member
    edited March 2004
    I'm going to bed, but here's what I've done thus far.

    Read my comments because you made numerous errors. Nothing that isn't uncommon, especially for beginning C students but still pitfalls you need to watch for.
    /********************************************************************************
    ** CIS 15 BG-03
    ** Fall,   2003
    ***************
    **
    ** Lab 4        Pointer Applications    20 Points
    **
    *************************************************
    
      Write a program that reads the size of an array from the keyboard. 
      The array is to be dynamically allocated in the heap. 
      Then the program reads integers from the keyboard into the array. 
    
      Modify the straight insertion sort from Chapter 8 so that it sorts
      the array into ascending order. 
      
      The program must not change the original array and must not create a
      copy of it. (See figure 10-25, page 515).
    
      Print the sorted array and the original array to a file, using the 
      following format:
    
      ==========   ===========   ============   
       ORIGINAL     ASCENDING     DESCENDING
      ==========   ===========   ============   
          50           20            100
          70           50             70
          20           50             70
         100           70             70
          70           70             50
          50           70             50
          70          100             20
    
      
      Data		:  Run  your program  twice:
    
        Test Data Set 1:
    
        10     here you enter the size of the array  
        10 10 30 30 40 50 50 50 60 60
    
    
        Test Data Set 2:
    
        25
        50 30 10 90 5 20 25 90 40 35 50 30 50 30 90 5 40 50 90 30 10 5 20 10 35
    
      NOTE: Use pointer notation throughout. Do not use an index to access the 
      elements in the array: use a pointer, as in the following example:
      ____________________________________________________________________
      YES
    
      int ary[10] = {10, 15, 10, 30, 40, 50, 60, 70, 80, 90 };
    
      int *pWalk;
      int *pLast;
    
      pLast = ary + 10 - 1;
      for( pWalk = ary; pWalk <= pLast; pWalk++ )
         printf( "%3d", *pWalk );
    
      _____________________________________________________________________
      NO
    
      int ary[10] = {10, 15, 10, 30, 40, 50, 60, 70, 80, 90 };
    
      int i;
    
      for( i = 0; i < 10; i++ )
         printf( "%3d", *(ary + i) );
     
    ****************************************
    **
    **  Written By:  First_Name Last_Name ???
    **
    **  Date: 2/6/02 - ???
    **
    ********************************************************************************/
    
    #include < stdio.h >
    #include < stdlib.h >
    //#include < crtdbg.h >
    
    #define maxSize 100
    /* Prototype Declarations */
    
    void welcome  (void);
    void farewell (void);
    void getData (int array[], int *arraySize);
    void sortArray (int array[]);
    void printArray (int array[], int arraySize);
    int main (void)
    {
    /* Local Definitions */
    	int array [maxSize];
    	int arraySize;
    
    /* Statements */
       welcome();
       getData(array, &arraySize);
       printArray(array, arraySize);
       
    //   printf( _CrtDumpMemoryLeaks() ? "Memory Leak\n" : "No Leak\n");
       farewell();
    
       return 0;
    
    } /* main */
    
    
    /* ============================== welcome ==============================
    	Prints a welcome message.
    	   PRE  : nothing
    	   POST : welcome message printed
    */
    void welcome (void)
    {
    /*  Local Definitions */
    
    /*  Statements */
    	printf("\t\t LAB 4 - Pointer Applications\n\n");
    	
    	return;
    
    } /* welcome */
    
    /* ============================== farewell ==============================
    	Prints a farewell message.
    	   PRE  : nothing.
    	   POST : farewell message printed
    */
    void farewell (void)
    {
    	printf("\n\t\tEnd of the program!"
    		   "\n\t\tHave a great day!\n");
    
    	return;
    
    } /* farewell */
    
    void getData (int array[], int *arraySize)
    {
    	int i;
    
    	printf("Array Size: ");
    // &arraySize? HUH? arraySize is a pointer.
    // You want the address of the pointer?  I doubt it.
    //	scanf("%d", &arraySize);
        scanf("%d", arraySize);
    
    // What?  arraySize is a pointer!  You're comparing the memory location of
    // arraySize to the value of i.  This isn't what you want!
    // Also, your for() had an ; before the {} meaning it was an EMPTY for
    // and that you were just scoping the two statements inside the {} but
    // they weren't scoped with the for().  Be careful of such things.
    // They're syntactically correct, but not what you intended.
    // Also, be careful.  You're using <= when you need <.
    //	for (i = 0; i <= arraySize; i++);
        for (i = 0; i < *arraySize; ++i)
    	{
    		printf("\nValue: ", i, *arraySize);
    		scanf("%d", (array + i));
    	}
    	return;
    }
    
    void printArray (int array[], int arraySize)
    {
    	FILE *fparray;
    	int i;
    	
    	fparray = fopen("array.txt", "w");
    
    // You had "fparray" (just like that, quoted) which was causing
    // fprintf() to die.
    
    	fprintf (fparray, "==========   ===========   ============\n");
    	fprintf (fparray, " ORIGINAL     ASCENDING     DESCENDING\n");
    	fprintf (fparray, "==========   ===========   ============\n");
    
    	for (i = 0; i <= arraySize; i++)
    	{
    		if (i %3 != 0)
    		{
    			fprintf(fparray, "%6d", *(array + i));
    		}
    		else
    		{
    			fprintf(fparray, "\n");
    			fprintf(fparray, "%6d", *(array + i));
    		}
    	}
    	scanf("%d", i);
    	
    	return;
    }
    
    void sortArray (int array[])
    {
    	return;
    }
    

    You'll notice I got rid of all of the array stuff and replaced it with (array + i).
  • edited February 2005
    I guess this is not place I ask it, but... could anyone do the program with class object in C++?
  • edited February 2005
    could anyone do it with class object in C++?
Sign In or Register to comment.