HI,
I am reading a text file and then adding 1 to each element and displaying it.
the code is as follows:
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
string line;
ifstream fnamet("abc.txt");
int Rows=0,Columns=0;
int relR,relG,relB,count;
if (fname.is_open())
{
while (! fname.eof() )
{
int i=0,a[4];//taken no of columns < =4
getline (fname,line);
istringstream tSS( line );
while( ! tSS.eof())
{
tSS>>a[i];
i++;
}
//if(Columns<2&&i>1) Columns=i;
if(i>3)
{
R=a[0]+1;
G=a[1]+1;
B=a[2]+1;
count=a[3];
printf("%d %d %d %d\n",R,G,B,a[3]);
}
}
printf("Rows=%d Columns=%d\n",histRows,histColumns);
fname.close();
}
else cout << "Unable to open file";
return 0;
}
Tha above code doesnt show any problem and shows the output.
Now I need to enter those values in a array as follows.
array[R][G][b] = count;
and my array size is 128*128*128.
If i am trying to do above, it doesnt show any compiling errors, but output is not generated. Shows that .exe file stopped working.
Pls help me how to achieve this.
Thanks,
Rishi
9 1495
ifstream fnamet("abc.txt");
int Rows=0,Columns=0;
int relR,relG,relB,count;
if (fname.is_open())
{
while (! fname.eof() )
Here you have a file pointer called fnamet, but your loops are to do with a filepointer called fname.
This says you are using Windows:
#include "stdafx.h"
so you should be using the RGB structure of Win32.
Yes I am using windows.
So wats the problem with the code.
Though it doesnt show any errors and gets compiled.
When showing the output it simply outputs .exe file stopped working.
Please help.
Thanks!!
Better send your stdafx.h so I can get this to compile.
Also, I need a sample of your input file.
Hi,
Here is my stdafx.h file
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
and my sample text file is as follows:
12 23 45 65
89 34 9 43
95 32 65 39
pls help!!
Thanks!!
-
//#include "stdafx.h"
-
#pragma once
-
-
-
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
-
#include <stdio.h>
-
#include <tchar.h>
-
-
#include <iostream>
-
#include <fstream>
-
#include <string>
-
#include <sstream>
-
using namespace std;
-
-
int main ()
-
{
-
string line;
-
//ifstream fnamet("abc.txt");
-
ifstream fname("c:\\scratch\\instructor\\abc.txt");
-
int Rows=0,Columns=0;
-
int relR,relG,relB,count;
-
if (fname.is_open())
-
{
-
while (! fname.eof() )
-
{
-
int i=0,a[4];//taken no of columns < =4
-
getline (fname,line);
-
istringstream tSS( line );
-
while( ! tSS.eof())
-
{
-
tSS>>a[i];
-
i++;
-
}
-
-
//if(Columns<2&&i>1) Columns=i;
-
if(i>3)
-
{
-
/*
-
R=a[0]+1;
-
G=a[1]+1;
-
B=a[2]+1;
-
count=a[3];
-
-
-
printf("%d %d %d %d\n",R,G,B,a[3]);
-
*/
-
relR=a[0]+1;
-
relG=a[1]+1;
-
relB=a[2]+1;
-
count=a[3];
-
-
-
printf("%d %d %d %d\n",relR,relG,relB,a[3]);
-
-
}
-
}
-
//printf("Rows=%d Columns=%d\n",histRows,histColumns);
-
printf("Rows=%d Columns=%d\n",Rows,Columns);
-
-
fname.close();
-
}
-
else cout << "Unable to open file";
-
return 0;
-
}
-
This does what you programmed. I didn't know what histRows and histColimns are so I fudged it.
Hi,
Thanks for the help. The histRows and HistColumns are just the Rows and Columns.
The above program works properly. The problem is coming when I am trying to do the following. I am adding the following code in this place
if(i>3)
{
relR=a[0]+1;
relG=a[1]+1;
relB=a[2]+1;
count=a[3];
/*add the code at this place
initialize a 3D array of size 128*128*128 and at this place add the following
array_3D[relR][relG][relB] = count; */
printf("%d %d %d %d\n",relR,relG,relB,a[3]);
}
There are no compiling errors but while looking at the output it shows .exe files stopped working.
Please help.
I need to enter the count values into a 3d array at the position of array_3d[relR][relG][relB].
Thanks!!
128 x 128 x 128 = 294912.
As an array this is fine. As a stack array, this is way too big. -
int array[128][128][128]; //wrong! probably exceeds your stack memory allowance
-
int (* array1)[128][128] = new int[128][128][128]; //OK
-
HI Thanks for the help!!
It worked.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: asdf |
last post by:
Hello!
Can someone tell me whats wrong with this piece of code:
Option Compare Database
Option Explicit
Sub retrieve()
Dim rst As ADODB.Recordset
Dim i As Integer
|
by: Paul Tremblay |
last post by:
Hi All,
I am a veteran C/C++ programmer (Unix background) and I want to get to
speed with Visual Studio .Net
I have legacy C/C++ code that I want to use in my application. However,
I'm not...
|
by: Showjumper |
last post by:
Whats the diff between the 2 and when do you use one and not the other?
|
by: buc |
last post by:
I have a simple combox on the screen that is bound via a datareader to a
stored proc in sql that returns a simple string. The code is
'load stored proc then
dReader =...
|
by: Vaidas Gudas |
last post by:
I has web project on virtual pc, maked with framework 2.0. there I was used
the method role.roleexists("admin") and everything was worked good.
but when i replace this project on my local machine,...
| |
by: sophie |
last post by:
Whats going on here:
Read in a number as a string:
scanf("%s", &number);
number = 12345, for arguements sake
Print it like this its fine:
|
by: Aaron Gray |
last post by:
Whats going on with setAttribute on IE it appears to work on some examples
and working code but not on other code that I am writting ?
<style>
.foo {
font-size: 200%;
}
</style>
|
by: LoneHunter01 |
last post by:
Basically, I just need a general direction on where to go for this. Yes, this is for a school project, though it's strictly an optional one (and I have tried many solutions, one in-depth). We've...
|
by: islayer |
last post by:
can someone tell me what is wrong with the bold code? i am just learning perl. the program should create a perl file with a random name (5 letters, followed by a number), but the name is always just...
|
by: x40 |
last post by:
I try to learn python thru solving some interisting problem, found
google trasure hunt,
write first program ( but cant find whats wrong).
# Unzip the archive, then process the resulting files to...
|
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,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |