Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

simple but strange problem(plz help,a bit urgent)

Posted on 2004-04-18
2
Medium Priority
?
233 Views
Last Modified: 2010-04-01
I want to code a program so as to be able to read the contents(which is just numbers) of a file.This is what i have done:

--------------------------------------------------
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;
int f,o,u1,u,w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,count,v1,v2,v,l1[20],l2[20],l3[20],mx1[4],my1[4],mz1[4],m,z,q,y,int1,int2,int3,i1,j1,q1,q2,q3,q4,ux,uy,uz,rx,ry,rz,mx ,mz ,my ,txx, txy, txz  ,tyx, tyy, tyz , tzx, tzy, tzz ,hz ,hy ,hx ,Jxx ,Jyy ,Jzz ,Jxy, Jxz ,Jyx ,Jyz ,Jzx ,Jzy;
int a[3][3];
unsigned long c[3][1];
int d1[100][100];
int d2[100][100];
int d3[100][100];
int h[3][1];
int b[3][1];
int f1,f2,i,l,j,k,t,A=2,B=2,n;  
int temp1,temp2,temp3;    

int main()

{
    ifstream  ifs ("inp.txt");
    ifstream in_stream1;
      ifstream in_stream2;
      ifstream in_stream3;
      ofstream out_stream1;
      ofstream out_stream2;
      ofstream out_stream3;
      FILE *stream1,*stream4;
    stream1 = fopen( "infile2.txt", "r+" );
    stream4  = fopen( "outfile1.txt", "r+" );
      in_stream1.open("infile2.txt");
    if (in_stream1.fail())
    {
        cout << "Input file opening failed.\n";
        exit(0);
    }
      
      out_stream1.open("outfile1.txt");
    if (out_stream1.fail())
    {
        cout << "Input file opening failed.\n";
        exit(0);
    }

for (f = 0;f <= 11; f++)
{
in_stream1 >> c[f][0];
cout << c[f][0];
}
out_stream1 << endl;
cout << endl;

return(0);       
        
        
    in_stream1.close();
      out_stream1.close();
    }
 
--------------------------------------------------

and this is the file's contents:

3
6
5
8
6
7
4
5
2
3
1
9

with these specific numbers the program can only read six or seven characters!!But with other numbers e.g:

2
5
4
3
5
4
1
5
2
7
2
4

it can read all of them.What do you think the problem is?
I am using VC++ 6.0
0
Comment
Question by:daemian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
rstaveley earned 600 total points
ID: 10854494
You need to simplify this a great deal.

> unsigned long c[3][1];

You have a 2D array here dimensioned 3 x 1

>for (f = 0;f <= 11; f++)
>{
>in_stream1 >> c[f][0];
>cout << c[f][0];
>}

When f is > 2, this should go kaboom.

0
 

Author Comment

by:daemian
ID: 10855443
right...so easy.I guess i stayed too much in front of the comp.thanks
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question