I have the following problem: My program is supposed to read data from files to an array. The files are numbered: capture[1].bmp,capture[2].bmp and so on. And I really don't want to do the same step for so many times. Is there a way to write a loop along the lines of
for (int i=1; i<25, i++);
{
fopen ("C:\capture[i].bmp","r")
fread(ch,sizeof(ch),1,fp);
.....
}
In other words, is there a way to insert the "i" variable into the filename?
Thank you for your insights.
6 4378
I have the following problem: My program is supposed to read data from files to an array. The files are numbered: capture[1].bmp,capture[2].bmp and so on. And I really don't want to do the same step for so many times. Is there a way to write a loop along the lines of
for (int i=1; i<25, i++);
{
fopen ("C:\capture[i].bmp","r")
fread(ch,sizeof(ch),1,fp);
.....
}
In other words, is there a way to insert the "i" variable into the filename?
Thank you for your insights.
Yes, there is: -
fopen ("C:\capture[" + i + "].bmp", "r");
-
Yes, there is: -
fopen ("C:\capture[" + i + "].bmp", "r");
-
thank you...................but i f i do that it's showing an error like
expression must have integral type
fopen ("C:\capture[" + i + "].bmp", "r");
actually wht is that + i + operator..............to use that we have to include any headre file
thank you...................but i f i do that it's showing an error like
expression must have integral type
fopen ("C:\capture[" + i + "].bmp", "r");
actually wht is that + i + operator..............to use that we have to include any headre file
I believe your error is being caused by an int being inserting into a string, I would recommend using a stringstream to convert the int to a char/string that can then be used in that fashion.
Your file isn't opening. Since you don't check that, you wouldn't know.
The problem is the path. \c is a carriage return and not two characters \ and c.
Try -
fopen ("C:\\capture[i].bmp","r");
-
Besides you didn't have a ; at the end of your fopen si the code may not have compiled at all.
The next thing is to get the [i] outdside the literal (see Post #2).
Your file isn't opening. Since you don't check that, you wouldn't know.
The problem is the path. \c is a carriage return and not two characters \ and c.
Try -
fopen ("C:\\capture[i].bmp","r");
-
Besides you didn't have a ; at the end of your fopen si the code may not have compiled at all.
The next thing is to get the [i] outdside the literal (see Post #2).
Thank You for ur suggetion...........
but if i do the same also same thing means it's opening the file but it's not reading any thing from file
fopen ("C:\\capture[k].bmp", "r");
fread(&ch,sizeof(ch),1,fp);
fclose(fp);
fopen ("C:\\capture[k].bmp", "r");
Your file is not opening because the file name is not C:\capture[k].bmp.
Its probably something like C:\capture25.bmp
So you need to build the file name correctly.
Apparently you are using C: -
char* filename[80];
-
filename[0] = '\0';
-
strcat(filename, "C:\\capture");
-
strcat(filename, k + '0'); //convert the int to a char
-
strcat(filename, ".bmp");
-
FILE* f = fopen(filename, "r");
-
if (f == NULL)
-
{
-
printf("file did not open\n");
-
exit(1);
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brandon McCombs |
last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm
trying here.
I have a C++ book by Deitel and Deitel that says I can use fstream
File("data.dat", ios::in | ios::out |...
|
by: Stampede |
last post by:
Hi,
I write an application which waits for incomming files in a specified
directory. I thought, that using the FileSystemWatcher would be the best, as
it does exactly what I need.
But now I have...
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: jsale |
last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app
i have made is running on IIS v6 and consists of a number of pages that allow
the user to read information from the...
|
by: svijay |
last post by:
hi
I have got a strange problem. May I know any solution for this.
Here is the detailed description about the problem
We have got a mainframe system and also production and development...
|
by: cybersangeeth |
last post by:
Hi,
I need to read 1KB each time from multiple files in a folder and pass
it to a byte array in a struct to be sent through a socket. I'm a C++
newbie. I managed to read 1KB each time from one...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: HC |
last post by:
Hello, all, I started out thinking my problems were elsewhere but as I
have worked through this I have isolated my problem, currently, as a
difference between MSDE and SQL Express 2005 (I'll just...
|
by: stephen |
last post by:
Hi,
I have 5 excel files and they have multiple sheets. I have to read (say
sheet 3) of each of the 5 excel files and consolidate them into one. what's
the best way to achieve this. if someone...
|
by: bkamrani |
last post by:
Hi Python gurus,
I have installed numpy and interested in testing f2py module using the
first example in the documentation.
First I tried:
C:\test>python "C:\Program...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |