Code:hi everyone, need some help using parallel arrays if the user inputs 1 4 5 4 3 3 1 3 5 how can i set up 3 parallel arrays to record these values?
This is a discussion on Parallel arrays within the C Programming forums, part of the General Programming Boards category; Code: hi everyone, need some help using parallel arrays if the user inputs 1 4 5 4 3 3 1 ...
Code:hi everyone, need some help using parallel arrays if the user inputs 1 4 5 4 3 3 1 3 5 how can i set up 3 parallel arrays to record these values?
Exactly which part of the question do you want help with??
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Here's an example of something similiar:
Code:#include <stdio.h> #include <stdlib.h> int *getrow(int length) { int i, ii, ch, *row=malloc(length*sizeof(int)); char buffer[16]; printf("Enter %d numbers seperated by commas\n" "(max 4 digits): ", length); for (i=0; i<length; i++) { ii=0; while ((ch=fgetc(stdin))!=',') { if (ch=='\n') break; buffer[ii]=ch; ii++; } buffer[ii]='\0'; row[i]=atoi(buffer); } return row; } void showmatrix (int *matrix[], int rows, int cols) { int i, ii; for (i=0; i<rows; i++) { for (ii=0; ii<cols; ii++) printf("%5d", matrix[i][ii]); printf("\n"); } } int main(int argc, char *argv[]) { int rows, cols, i, **matrix; if (argc<3) { printf("Usage \"%s [NO OF ROWS][NO OF COLS]\", eg %s 3 3\n",argv[0],argv[0]); return 0; } rows=atoi(argv[1]); cols=atoi(argv[2]); matrix=malloc(rows*sizeof(int*)); for (i=0; i<rows; i++) matrix[i]=getrow(cols); showmatrix(matrix,rows,cols); for (i=0; i<rows; i++) free(matrix[i]); free(matrix); return 0; }
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge