Hello , I'm new on programming and I'm trying to pass one more step to files. I wrote the following code and opened the " dosya.txt " file to true folder. At first I wrote it to G:\\dosya.txt , then I got null character as a return. After this I changed it to C:\\dosya.txt , now I got
" Unhandled exception at 0x5521e42e (msvcr100d.dll) in asd.c.exe: 0xC0000005: Access violation writing location 0xcccccccc. " error and I don't know how to solve it. I think I didn't do anything wrong but my code doesn't work. Can you help me to solve this ? Thanks a lot :) - #include <stdio.h>
-
#include <stdlib.h>
-
int main()
-
{
-
int i,a[5];
-
FILE *ptr;
-
ptr = fopen("C:\\dosya.txt","r");
-
if(ptr==NULL)
-
printf("File does not exist !");
-
for(i=0;i<5;i++,ptr++)
-
{
-
fscanf(ptr,"%d",a[i]);
-
printf("%d\n",a[i]);
-
}
-
}
I have compiled after modification, anyway try this:
(I have compiled too, and it runs) -
#include <stdio.h>
-
#include <stdlib.h>
-
int main()
-
{
-
int i;
-
int a[]={19,21,9,3,75}; //initialize array
-
FILE *ptr;
-
ptr = fopen("C:\\dosya.txt","w");
-
if(ptr==NULL)
-
printf("File does not exist !");
-
-
-
for(i=0;i<5;i++)
-
{
-
fprintf(ptr,"%d",a[i]); //write to file
-
}
-
-
rewind (ptr); //reset file pointer
-
-
for(i=0;i<5;i++)
-
{
-
fscanf(ptr,"%d",a[i]); //read from file
-
printf("%d\n",a[i]);
-
}
-
-
fclose (ptr);
-
-
}
-
3 3209
Here is an answer: -
//don't increase ptr manually, it's done by internal
-
for(i=0;i<5;i++,ptr++)
-
-
//this is the right format
-
for(i=0;i<5;i++)
-
I just done what you've said but it still doesn't work. I got same error message :(
I have compiled after modification, anyway try this:
(I have compiled too, and it runs) -
#include <stdio.h>
-
#include <stdlib.h>
-
int main()
-
{
-
int i;
-
int a[]={19,21,9,3,75}; //initialize array
-
FILE *ptr;
-
ptr = fopen("C:\\dosya.txt","w");
-
if(ptr==NULL)
-
printf("File does not exist !");
-
-
-
for(i=0;i<5;i++)
-
{
-
fprintf(ptr,"%d",a[i]); //write to file
-
}
-
-
rewind (ptr); //reset file pointer
-
-
for(i=0;i<5;i++)
-
{
-
fscanf(ptr,"%d",a[i]); //read from file
-
printf("%d\n",a[i]);
-
}
-
-
fclose (ptr);
-
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ramsin.savra |
last post by:
Hi,
I'm using same code for opening a TIFF file in VC++ works just fine but
under linux it says unable to open the tiff file!
Any comment on this?
if (argc < 2)
{
cout << "Not enough...
|
by: Lee Crabtree |
last post by:
I've got a solution that has a C++ project that compiles to a DLL, and a
C# project that is the main piece of the program.
The DLL is managed C++ on top of regular C++. In one of the native...
|
by: aham |
last post by:
Hi everyone,
I wrote code for authentication, after a user enters userid and password, it should open a file, which will be taken from a database. Code is taking he file name properly, but it is...
|
by: siricharan82 |
last post by:
Hi Everybody.
I have a problem on .NET while opening.
Actually before that it works normally.But one day it does not opening.
I dont know the reason why it is happend like that.
Even I am...
|
by: amit.atray |
last post by:
Hi,
I am trying to open an ISAM file with isopen call.
But I am getting error with iserror set to 111.
I tried to check 111 error code ...
111 ENOREC
Action: No record could be found...
|
by: ranjukbs |
last post by:
Hi All,
I am facing problem with opening a external url from menu. If i link it directly with "www" url its appening relative path along with the external url. I want this to open in same window....
|
by: Wayne |
last post by:
I'm having a problem that I've seen before on XP and am now seeing on
Vista. It started yesterday and I can't associate it with anything
that I've done to the PC, like installing software etc. I...
|
by: Sanjeeva K kanakam |
last post by:
Hi all, I am developing one application. In that i have created on report file which contains tables, titles and tree view list also by using HTML tags. I am opening this file in my application it...
|
by: manu |
last post by:
Hi,
Can anyone please tell me the difference of opening file in Binary
mode or in Text mode?
|
by: premMS143 |
last post by:
Dear all,
In our company, we are using a system having windows XP & Office 2007 installed. Since from last 1 week we are facing problem with opening office files. All office files icons are changed...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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...
| |