![]() |
| | #1 |
| Registered User Join Date: Sep 2004
Posts: 16
| Trouble storing file input in array Code: char read, array[3][3];
int i=0, j=0;
FILE *test = fopen("test.txt","r");
while (!feof(test))
{
fscanf(test, "%c", &read);
if (read=='\n')
break;
else
array[i][j]=read;
if (i<3 && j<3)
j++;
else if (i<3 && j==3)
i++;
}
|
| difficult.name is offline | |
| | #2 | |
| Registered User Join Date: Oct 2004
Posts: 11
| Quote:
for example you might have the file be something like: abc 123 xyz you code will read in abc and then detect a newline('\n') and break. You may try: Code: while (!feof(test))
{
fscanf(test, "%c", &read);
if (read=='\n')
{
j = 0; //reset j
i++; //increase to next line
continue; //go back to top of loop
}
j++;
}
Ryan | |
| PrimeTime00 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Memory Address | kevinawad | C++ Programming | 18 | 10-19-2008 10:27 AM |
| Need Help Fixing My C Program. Deals with File I/O | Matus | C Programming | 7 | 04-29-2008 07:51 PM |
| Trouble with file input | w274v | C Programming | 6 | 12-18-2005 04:40 AM |
| Post... | maxorator | C++ Programming | 12 | 10-11-2005 08:39 AM |
| Reading strings from a file and storing into an array | Rizage | C++ Programming | 1 | 10-24-2002 03:04 AM |