LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem with writing in a text file in C (https://www.linuxquestions.org/questions/programming-9/problem-with-writing-in-a-text-file-in-c-507750/)

manolakis 12-05-2006 05:00 PM

Problem with writing in a text file in C
 
Hey there
It will be great if someone could help me with the following case
I recently found a C program on the net and i compiled and everything was fine
The program starts by passing parameters in the terminal a text file to read and another to write. Well, reading goes well. The problem is there is nothing in the output text file. I checked my permissions which were good as well.
Any ideas?

Tinkster 12-05-2006 05:12 PM

Might help to see the relevant piece of code? :}


Cheers,
Tink

manolakis 12-06-2006 09:08 AM

Well, to be honest with you i thought about it before.
The fact is that the code is too long and is regarded to Counter Propagation Neural Networks in Artificial Intelligence so that's why i didnt post it.
http://www.cis.syr.edu/~mohan/html/Bookfiles/counter.c
There is also a README txt in http://www.cis.syr.edu/~mohan/html/B...ME-for-counter which i strongly believe that it would be useful.

Wim Sturkenboom 12-06-2006 10:19 AM

You need to pass three files in total. Sounds like you only pass two.

manolakis 12-06-2006 10:32 AM

The fact is that in output generation (-o) i pass 3 files as i am told
I noticed also that if i pass an output file which doesnt exist after the compilation will be produced, but will not be opened by a default program lets say by KWrite.
If i try then to open it with KWrite will be empty.

Wim Sturkenboom 12-06-2006 10:18 PM

It works (at least my outputfile is not empty). I started with an empty data file before I could generate the weight file. Next it went smoothly.
Code:

wim@btd-techweb01:~/progs/lq507750$ ./lq507750 -o weight1 data1 out1
Unable to open file weight1 for reading
wim@btd-techweb01:~/progs/lq507750$ ./lq507750
** Select L(earning) or O(utput generation) **
L
How many dimensions does the input pattern have?: 2
How many dimensions does the output pattern have?: 3
How many hidden nodes will the network use?: 4
Enter the name of the training data file: data1
Unable to open file data1 for reading
wim@btd-techweb01:~/progs/lq507750$ touch data1
wim@btd-techweb01:~/progs/lq507750$ ./lq507750
** Select L(earning) or O(utput generation) **
L
How many dimensions does the input pattern have?: 2
How many dimensions does the output pattern have?: 3
How many hidden nodes will the network use?: 4
Enter the name of the training data file: data1
Enter the name of the output weight file: weight1
Total number of input samples?: 5
Max number of iterations in phase 1(enter a positive integer)?: 6
Max number of iterations in phase 2(enter a positive integer)?: 7
Enter 0 to use default values for learning rate parameters, enter 1 for user-specified values
  (default learning rates decay exponentially from 0.3 to 0.01): 0
Elapsed time 0 milliseconds

wim@btd-techweb01:~/progs/lq507750$ ./lq507750 -o weight1 data1 out1
Elapsed time 10 milliseconds
wim@btd-techweb01:~/progs/lq507750$ ls -l
total 92
-rw-r--r--  1 wim develop    0 2006-12-07 05:54 data1
-rwxr-xr-x  1 wim develop 23400 2006-12-07 06:03 lq507750*
-rw-r--r--  1 wim develop 22390 2006-12-07 06:03 lq507750.c
-rw-r--r--  1 wim develop 40000 2006-12-07 06:05 out1
-rw-r--r--  1 wim develop  194 2006-12-07 06:05 weight1
wim@btd-techweb01:~/progs/lq507750$

There are a number of warnings when using the -Wall option when you compile the source code. You might want (or have to) to clear them out first.

PS gcc 3.3.4 on slackware 10.1


All times are GMT -5. The time now is 03:44 AM.