473,796 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

input and output file (txt file)

16 New Member
Hi...
I've been trying to make a program where the input is txt file, and the output will be saved in txt file. But, I keep getting error Message.
My code looks like this:
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main (){
  5.     int i,j;
  6.     float H [100][100];
  7.  
  8. FILE*in;
  9. in=fopen("0.txt","rt");
  10. FILE*out;
  11. out=fopen("rotation0.txt","w");
  12. if(in){
  13.   for(i=0;i<100;i++)
  14.     for(j=0;j<100;j++)
  15.       fscanf(in, "%f", &H[i][j]);
  16.   for(i=0;i<100;i++){
  17.     for(j=0;j<100;j++)
  18.       //printf("%d "H[i][j]);
  19.       printf("");;
  20.     }
  21.   }
  22. else {
  23. fprintf(stderr,"Cannot open file\n");
  24. return 1;
  25. }
  26.  for(i=0;i<100;i++){
  27.    for(j=0;j<100;j++){
  28.      printf("[%d][%d]=%f\n ",i,j,H[i][j]);
  29.      fprintf(out,"[%d][%d]=%f\n ",i,j,H[i][j]);
  30.    }
  31.  }
  32.  
  33. return 0;
  34. fclose(in);
  35. fclose (out);
  36. }
  37.  
The error message says:
"parse error before *"
" "out" undeclared"

I found a couple strange things; if I move FILE*in (line 8&9) below FILE*out (line 10&11), the error became:" "in" undeclared".
And if I use different compiler (I'm using cygwin currently), it works. unfortunately, I can't use the other compiler because it doesn't work if I increase the size of array.

Could you help me, please?

Thank you
Jun 7 '09 #1
1 2531
JosAH
11,448 Recognized Expert MVP
Swap lines #9 and #10; in C first define your variables, then use them in statements etc.

kind regards,

Jos
Jun 7 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4588
by: slickn_sly | last post by:
For some reason, I'm getting an error. It doesn't seem to be reading my "input.txt" file. I'm trying to read the "input.txt" file which consits of random integers and use insertion sort to sort them in order. Then, i want to have the sorted integers go the file "output.txt" static final int MAX_NUM = 100; public static void main( String args ) throws java.io.IOException {
6
1832
by: Eric Lavigne | last post by:
Here is a shell command (MS-DOS): debug\curve-fit <input.txt >output.txt And here is a Python script that *should* do the same thing (and almost does): import os inputfilename = 'input.txt' outputfilename = 'output.txt'
3
1938
by: Kostadis.Spirou | last post by:
this is a programm that opens config.txt and reads the 2 lines that are inside it,after that it copies them and i want to put them as parametres at ifstream examplefile (file1.data()); ofstream fout (file2.data()); but when i try to run it it doesn't work at all. any suggestions what to change in my code? #include <iostream>
7
7537
by: MM | last post by:
Hi there, How can I change my code (below) so that I use an "input argument" to specify the file name of the input file? For example, if I compile the code and that the application then gets the name "splitdata", then I want to be able to call my application with something like this (datafile.txt will then be the name of the input file): splitdata datafile.txt
1
1845
by: Aalok | last post by:
This is what i want to do. Read a text file as an input and based on that file, Create an outpu text file which saves the contents of the input file in a specifi format in the output file. I know how to read a text file and i can even display the contents o the input file on the prompt. However i am trying to figure out how t save the contents of the input file in a specific manner.
4
6217
by: Carlo Marchesoni | last post by:
I really don't achieve to read a simple 'input.txt' with the following content: Jürg (Hex: 4a fc 72 67) to an identical 'output.txt' I do the following (and tried with tons of different encodings): private static void WriteFile() { StreamWriter sr = File.CreateText("Output.txt"); try { using (TextReader tr = new StreamReader(new
5
6091
by: jwright | last post by:
I have decided to use a struct to collect my data. The input file is comma dilineated between almost all of the fields. Here is the code I have so far and a sample input and output file. #include <fstream> #include <iostream> #include <iomanip> using namespace std; struct pyrll
5
756
by: Dic4000 | last post by:
ÏÂÃæ³ÌÐò½¨Á¢²»ÁËÎļþ,²»ÖªµÀÄÄÀï³ö´íÁË? Ö»Ï붨ÒåÒ»¸öfstreamÀàÐÍÀ´Íê³ÉÊäÈëÊä³öµÄ¹¤×÷. #include<iostream> #include<conio.h> #include<fstream> using namespace std;
116
4642
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however, when I run it, it stalls and does nothing. I'm wondering if there's something obvious that I'm missing. My code is below and any help would be appreciated. Thanks, Dave
1
2673
by: dwaterpolo | last post by:
Hi Everyone, I am trying to read two text files swY40p10t3ctw45.col.txt and solution.txt and compare them, the first text file has a bunch of values listed like: y y y y y y y
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.