View Single Post
  #1 (permalink)  
Old 04-26-2008, 08:38 AM
kckc314 kckc314 is offline
Novice
Join Date: Apr 2008
Posts: 14
iTrader: (0)
kckc314 is on a distinguished road
read data from a file

when reading data from the attached file, apart from the four corner which only associated with #s, how to only grap the data inside the 4 #s border, which are numbers 0-9 and some #s in the middle and store them into 2d array? i only want to store the numbers and the #s between the numbers inside. there is a space in between numbers and #s. there are some spaces, new line character at top, bottom, left and right of the square. below are the codes that i implemented but kind of stuck in some way as may need your help to carry on.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

#define row 12      /* Number of rows on square */
#define col 12      /* Number of columns on square */

int square[row][col];
int i = 0, j = 0, ch;

int main(int argc, char *argv[]) {
    
    while ((ch = getchar()) != EOF) {
          if (ch >= 0 || ch <= 9) {
             for (i = row; i >= 1; i--) {
                 for (j = ch; j <= 23; j++) {
thanks in advance.
Attached Files
File Type: txt test.txt (516 Bytes, 1 views)

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote