473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with reading multiple files

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.
Oct 1 '07 #1
6 4378
ilikepython
844 Expert 512MB
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:
Expand|Select|Wrap|Line Numbers
  1. fopen ("C:\capture[" + i + "].bmp", "r");
  2.  
Oct 1 '07 #2
Yes, there is:
Expand|Select|Wrap|Line Numbers
  1. fopen ("C:\capture[" + i + "].bmp", "r");
  2.  


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
Oct 1 '07 #3
sicarie
4,677 Expert Mod 4TB
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.
Oct 1 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
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

Expand|Select|Wrap|Line Numbers
  1. fopen ("C:\\capture[i].bmp","r");
  2.  
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).
Oct 1 '07 #5
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

Expand|Select|Wrap|Line Numbers
  1. fopen ("C:\\capture[i].bmp","r");
  2.  
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);
Oct 3 '07 #6
weaknessforcats
9,208 Expert Mod 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. char* filename[80];
  2. filename[0] = '\0';
  3. strcat(filename, "C:\\capture");
  4. strcat(filename, k + '0');     //convert the int to a char
  5. strcat(filename, ".bmp");
  6. FILE* f = fopen(filename, "r");
  7. if (f == NULL)
  8. {
  9.      printf("file did not open\n");
  10.      exit(1);
  11. }
  12.  
Oct 3 '07 #7

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

Similar topics

8
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 |...
3
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...
0
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....
7
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...
1
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...
5
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...
6
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;
9
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...
3
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
jinu1996
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...
0
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...

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.