Ok I tried fopen to open a file called file1.txt, but it said file1 is undeclared or something like that. What's the proper code to open a file in C (if I want to open file1.txt)?
How to open a file with a c program.?
just declare a file pointer for eg FILE* f ,then
f=fopen("drive letter:\file1.txt","mode");
mode work
"a" append can make changes at the end of file
"r" read you can just read the file cant chang in this mode
"w" write you can write any where in your file
Tuesday, July 14, 2009
How can I create multiple output text file in C using turbo C?
I have a text file containing number of lines (not fixed). I want to write a programme which will create separate text file containing each line. How to do this using C in Turbo C. Anybody please help me and please tell it in detail.
How can I create multiple output text file in C using turbo C?
Use the below code as a reference......
#include "stdio.h"
#include "stdlib.h"
void main( )
{
FILE *fp;
char c;
int i=1;
fp = fopen("TENLINES.TXT", "r"); // Open the file to be read
if (fp == NULL) printf("File doesn't exist\n");
else {
// perform the loop until EOF
while(!feof(fp)) {
// Read a single line.....
if(fgets(str, 126, fp)) {
printf("%s", str);
//createfile(" Call create file function from here....
................
..................
}
}
}
fclose(fp);
}
void createfile(char* filename,char* content)
{
FILE *fpwrite;
int index;
fpwrite = fopen(filename,"w"); /* open for writing */
strcpy(stuff,content);
for (index = 1; index %26lt;= 10; index++)
fprintf(fpwrite,"%s Line number %d\n", stuff, index);
fclose(fpwrite); /* close the file before ending program */
}
Reply:http://www.thescripts.com/forum/thread49...
hope this will help
Cheers:)
How can I create multiple output text file in C using turbo C?
Use the below code as a reference......
#include "stdio.h"
#include "stdlib.h"
void main( )
{
FILE *fp;
char c;
int i=1;
fp = fopen("TENLINES.TXT", "r"); // Open the file to be read
if (fp == NULL) printf("File doesn't exist\n");
else {
// perform the loop until EOF
while(!feof(fp)) {
// Read a single line.....
if(fgets(str, 126, fp)) {
printf("%s", str);
//createfile(" Call create file function from here....
................
..................
}
}
}
fclose(fp);
}
void createfile(char* filename,char* content)
{
FILE *fpwrite;
int index;
fpwrite = fopen(filename,"w"); /* open for writing */
strcpy(stuff,content);
for (index = 1; index %26lt;= 10; index++)
fprintf(fpwrite,"%s Line number %d\n", stuff, index);
fclose(fpwrite); /* close the file before ending program */
}
Reply:http://www.thescripts.com/forum/thread49...
hope this will help
Cheers:)
Compile errors in my header file? why? c++?
before in my header file i had this:
File Edit Options Buffers Tools C++ Help
#ifndef SWAP_H
#define SWAP_H
//#include %26lt;string%26gt;
//#include %26lt;iostream%26gt;
using namespace std;
void swap (string %26amp;, string %26amp;);
#endif
-------
that gave me these compile errors:
Swap.h:7: error: `string' was not declared in this scope
Swap.h:7: error: parse error before `,' token
------
now i have:
#ifndef SWAP_H
#define SWAP_H
//#include %26lt;string%26gt;
//#include %26lt;iostream%26gt;
using namespace std;
std::void swap (string %26amp;, string %26amp;);
#endif
------
Swap.h:7: error: `string' was not declared in this scope
Swap.h:7: error: parse error before `,' token
---
ALL this happens when i try to compile my Swap.cpp file.. help? wats wrong?
Compile errors in my header file? why? c++?
The compiler doesn't know what a "string" is.
uncomment the #include %26lt;string%26gt; and add
using std::string;
File Edit Options Buffers Tools C++ Help
#ifndef SWAP_H
#define SWAP_H
//#include %26lt;string%26gt;
//#include %26lt;iostream%26gt;
using namespace std;
void swap (string %26amp;, string %26amp;);
#endif
-------
that gave me these compile errors:
Swap.h:7: error: `string' was not declared in this scope
Swap.h:7: error: parse error before `,' token
------
now i have:
#ifndef SWAP_H
#define SWAP_H
//#include %26lt;string%26gt;
//#include %26lt;iostream%26gt;
using namespace std;
std::void swap (string %26amp;, string %26amp;);
#endif
------
Swap.h:7: error: `string' was not declared in this scope
Swap.h:7: error: parse error before `,' token
---
ALL this happens when i try to compile my Swap.cpp file.. help? wats wrong?
Compile errors in my header file? why? c++?
The compiler doesn't know what a "string" is.
uncomment the #include %26lt;string%26gt; and add
using std::string;
How to read Tiff file using C#???
I need to read a tiff file using C#, but am not getting what to do, what are steps do i need to take in .NET ( means which all dll is required to read and write and other steps).
After reading tiff file i need to trasfer the same format of tiff to TXt format.
Can any one help me... plz.............
How to read Tiff file using C#???
Read it as an array of bytes.
Reply:how to open tiff using C# Report It
wallflower
After reading tiff file i need to trasfer the same format of tiff to TXt format.
Can any one help me... plz.............
How to read Tiff file using C#???
Read it as an array of bytes.
Reply:how to open tiff using C# Report It
wallflower
Binary Tree for searching file in c++?
I wanna write a c++ program to search inside a file and build a binary tree of all those words inside the file. Anyone can help or send me the code if you have ??
Thankx
cgsupervisor@yahoo.com
Binary Tree for searching file in c++?
Here's some code in C, but it should compile just fine
under C++ (and you can "pretty it up" with C++ method
definitions to replace the C functions if you like):
http://nob.cs.ucdavis.edu/classes/ecs030...
Also, if your problem is no more sophisticated than what
you've described, you could read the words into an array
and call qsort() in probably 20 lines of code.
Thankx
cgsupervisor@yahoo.com
Binary Tree for searching file in c++?
Here's some code in C, but it should compile just fine
under C++ (and you can "pretty it up" with C++ method
definitions to replace the C functions if you like):
http://nob.cs.ucdavis.edu/classes/ecs030...
Also, if your problem is no more sophisticated than what
you've described, you could read the words into an array
and call qsort() in probably 20 lines of code.
I am using parser generator 2 to compile a file using C++ borland 6.?
using parser generator,when i am compiling the files with C++ borland 6,i face problem with heared and include files..and the error is:cant include %26lt;.....h%26gt; forexample..or another is:ERROR must use c++ ..or something like this.
may i kow if i should do any copy %26amp; paste files between parser and borland in include folders or..can some one help me to do the projects?i realy will be thank ful..i need to read characters from a file and define the TOKENs or lexical errors
I am using parser generator 2 to compile a file using C++ borland 6.?
Fully qualify your path names (not doc.txt, but C:\Documents and Settings\Administrator\My Documents\doc.txt). This guarantees that a "file not found" is a file that doesn't exist there.
An unsafe way around getting rid of those ERROR: Must use C++ is including (before the libraries) a #define __cplusplus line. That should work, considering that the safety responsible for that mechanism is:
#ifndef __cplusplus
#error Must use C++
#endif
may i kow if i should do any copy %26amp; paste files between parser and borland in include folders or..can some one help me to do the projects?i realy will be thank ful..i need to read characters from a file and define the TOKENs or lexical errors
I am using parser generator 2 to compile a file using C++ borland 6.?
Fully qualify your path names (not doc.txt, but C:\Documents and Settings\Administrator\My Documents\doc.txt). This guarantees that a "file not found" is a file that doesn't exist there.
An unsafe way around getting rid of those ERROR: Must use C++ is including (before the libraries) a #define __cplusplus line. That should work, considering that the safety responsible for that mechanism is:
#ifndef __cplusplus
#error Must use C++
#endif
What are the file read & write functions in C# ???
Actually i want to know that what are the file read %26amp; write functions in C#, like fputs(),fgets(), or fprintf(), and fscanf(); and please also mention how to open file in c# . and how to close it.......
please reply............
What are the file read %26amp; write functions in C# ???
Ok, what you're describing is C functions which the concept is expanded in C#. Several objects are used to read and write files. They include the buffered streams, file streams, text read/writers to name a few. Most fall under the system.io class or input/output class of structure. An example is demonstrated below:
using System;
using System.IO;
class FSRead
{
public static void Main()
{
//Create a file stream from an existing file.
FileInfo fi=new FileInfo("c:\\csc.txt");
FileStream fs=fi.OpenRead();
//Read 100 bytes into an array from the specified file.
int nBytes=100;
byte[] ByteArray=new byte[nBytes];
int nBytesRead=fs.Read(ByteArray, 0, nBytes);
Console.WriteLine("{0} bytes have been read from the specified file.", nBytesRead.ToString());
}
}
I've also included some links below.
Hope this helps.
hollyhock
please reply............
What are the file read %26amp; write functions in C# ???
Ok, what you're describing is C functions which the concept is expanded in C#. Several objects are used to read and write files. They include the buffered streams, file streams, text read/writers to name a few. Most fall under the system.io class or input/output class of structure. An example is demonstrated below:
using System;
using System.IO;
class FSRead
{
public static void Main()
{
//Create a file stream from an existing file.
FileInfo fi=new FileInfo("c:\\csc.txt");
FileStream fs=fi.OpenRead();
//Read 100 bytes into an array from the specified file.
int nBytes=100;
byte[] ByteArray=new byte[nBytes];
int nBytesRead=fs.Read(ByteArray, 0, nBytes);
Console.WriteLine("{0} bytes have been read from the specified file.", nBytesRead.ToString());
}
}
I've also included some links below.
Hope this helps.
hollyhock
Subscribe to:
Posts (Atom)