delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/09/11:01:16

From: north AT iname DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Two newbee questions
Date: Tue, 09 Feb 1999 15:33:43 GMT
Organization: Deja News - The Leader in Internet Discussion
Lines: 62
Message-ID: <79pkgm$ab4$1@nnrp1.dejanews.com>
NNTP-Posting-Host: 195.58.103.21
X-Article-Creation-Date: Tue Feb 09 15:33:43 1999 GMT
X-Http-User-Agent: Mozilla/4.04 [en] (Win95; I)
X-Http-Proxy: 1.0 x12.dejanews.com:80 (Squid/1.1.22) for client 195.58.103.21
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello!!!!!!!!

What is wrong in this program????
I'm very new to C, but I'm trying although...
Here is a program that is supposed to read two
text strings from a text file and put them into
two arrays left[] and right[].

The strings in the text file is delimited by a a tab
and are ending with a newline.

When running my creation I don't get the results that
I expect from the reading operation.

program:--------------
#include <stdio.h>

int main(void)
{
 int n;
 char left[50],right[50];
 FILE *file;

 file= fopen("text_file.txt", "r");

for(n=1;(!feof(file));++n){
 fscanf(file,"%[^\t]\t%[^\n]\n",left[n], right[n]);
 printf("%d %s\t%s\n", n, left[n], right[n]);
 fflush(stdout);
}
 fclose(file);
return 0;
}
----end-----

Text file(text_file.txt):-----
column 1 row 1	column 2 row 1
column 1 row 2	column 2 row 2
column 1 row 3	column 2 row 3
column 1 row 4	column 2 row 4
column 1 row 5	column 2 row 5
column 1 row 6	column 2 row 6
----end-----

And the result:---------------
1 (null)        column 2 row 1
2 (null)        (null)
3 (null)        (null)
4 (null)        (null)
5 (null)        (null)
6 (null)        (null)

And by the way, if I put Swedish characters
in the text file, the program does not put
out those characters to the stdout.
How do I get my program to read and write
with Swedish character set?

/north

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019