The Has to be a Better Way (???)

The Has to be a Better Way (???)

Post by nancy khawa » Thu, 01 Sep 1994 02:51:23



A friend of mine has written a small test program that will
get the next line of character data from a two-dimensional array.
I think ptext is kinda * to read though.  However, I cannot
make any better suggestions to him.  Can you?  Here's a copy of it:

#include <stdio.h>
#define MAX_LINES 100 /* Maximum lines of text */
#define MAX_CHARS 80  /* Maximum characters per line */
GetCharData(int (*text)[80]);

main()
{
        int text[MAX_LINES][MAX_CHARS]; /* 100 lines at 80 characters each */
        int lineData[4];     /* # of lines, Max, Min, and Avg */
        int (*ptext)[][80];

        ptext=&text;
        GetCharData(text);
        printf("Sizeof text: %d\n",sizeof(text));

Quote:}

GetCharData(int (*text)[80])
{
        char buf[80];
        int line=0;
        int count=0;
        int c;

        while (line < MAX_LINES && gets(buf) != NULL)
        {
                while (count < MAX_CHARS && (c=getchar()) != '\n')
                {
                        text[line][count++];
                }
                }
                text[line++][count];
        }

Quote:}

--
   Nancy K.