what is the problem in the below program
main()
{
char c[5]={'a', 'b', 'c', 'd', 'e'};
FILE *ptr;
int i;
ptr=fopen("C:\examples\file.dat","w");
printf("File opened");
for(i=0;i<5;i++)
{
while(c[i]!='e') {
putc(c[i],ptr); }
}
fclose(ptr);
}
8 1354
what is the problem in the below program
main()
{
char c[5]={'a', 'b', 'c', 'd', 'e'};
FILE *ptr;
int i;
ptr=fopen("C:\examples\file.dat","w");
printf("File opened");
for(i=0;i<5;i++)
{
while(c[i]!='e') {
putc(c[i],ptr); }
}
fclose(ptr);
}
Suppose the current character c[ i ] is not a lowercase 'e'. Variable 'i' isn't
changed in your while loop so your loop will only terminate when hell freezes
over (*)
kind regards,
Jos
(*) or when your computer breaks down or when the Cosmic Flying Spaghetti
Monster decides to destroy Earth ;-)
You really have a good imagination,Jos
Suppose the current character c[ i ] is not a lowercase 'e'. Variable 'i' isn't
changed in your while loop so your loop will only terminate when hell freezes
over (*)
kind regards,
Jos
(*) or when your computer breaks down or when the Cosmic Flying Spaghetti
Monster decides to destroy Earth ;-)
yes ...but the file is not being identified.
and no characters are entered
yes ...but the file is not being identified.
and no characters are entered
Use double slashes when defining file loaction.
savage
You are using while loop insede for loop. Hence, when c[i] is not equal to 'e', it goes into loop. Because while checks whether c[i] != 'e', in this case it is true. so, it doesn't come out from while loop.
what is the problem in the below program
main()
{
char c[5]={'a', 'b', 'c', 'd', 'e'};
FILE *ptr;
int i;
ptr=fopen("C:\examples\file.dat","w");
printf("File opened");
for(i=0;i<5;i++)
{
while(c[i]!='e') {
putc(c[i],ptr); }
}
fclose(ptr);
}
Use double slashes when defining file loaction.
savage
its working now
thanks a lot
You are using while loop insede for loop. Hence, when c[i] is not equal to 'e', it goes into loop. Because while checks whether c[i] != 'e', in this case it is true. so, it doesn't come out from while loop.
s I have corrected it now
thanks,
its working now
thanks a lot
Allways a pleasure...
Savage
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xah Lee |
last post by:
Just bumped into another irresponsibility in perl.
the crime in question this time is the module File::Basename.
Reproduction:
1. create a directory containing a file of this name:...
|
by: Hans-Joachim Widmaier |
last post by:
Hi all.
Handling files is an extremely frequent task in programming, so most
programming languages have an abstraction of the basic files offered by
the underlying operating system. This is...
|
by: microsoft.news.com |
last post by:
I have a text file that has a column of numbers that i need to add to get a
total of. Is there any way to add the number column in my text file?
the text file looks like this:
BMW ...
|
by: Greg Collins [MVP] |
last post by:
For background, please refer to my original thread: http://groups.google.com/groups?selm=efe5w7tYEHA.3112%40tk2msftngp13.phx.gbl
I've thought of a potential way around the issue, but I'm new to...
|
by: Shapper |
last post by:
Hello,
I created a script to upload a file.
To determine the file type I am using userPostedFile.ContentType.
For example, for a png image I get "image/png".
My questions are:
1. Where can...
|
by: Jonny |
last post by:
Hello Group
How do I open a Save File Dialog from an ASPX page behind a browse button?
Any help would be fantastic!!
I am using ASP.NET 1.1 using VB.NET as the coding language
TIA
|
by: iwdu15 |
last post by:
hi, how can i get the icon associated with a certain file type? thanks
--
-iwdu15
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed
using Apache's apxs and the php library was installed to
/usr/local/php. However, when I set my "error_reporting"...
|
by: JimmyKoolPantz |
last post by:
IDE: Visual Studio 2005
Language: VB.NET
Fox Pro Driver Version: 9.0.0.3504
Problem: I currently have a problem altering a DBF file. I do not get
any syntax errors when running the program. ...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Many websites have a form or a link you can use to download a file. You click a form button or click...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |