someone can give me example how to read from file
because i tried many ways and none of them work
Printable View
someone can give me example how to read from file
because i tried many ways and none of them work
PHP Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define BUFFER_SIZE 1000
int main()
{
FILE* FilePointer;
int Variable;
char cBuffer[BUFFER_SIZE+1];
Variable = 42;
/* open for writing a file named test.txt on C: */
FilePointer = fopen( "C:\\test.txt", "w" );
/* check if successfull */
if( FilePointer == NULL )
{
printf( "Unable to open file for writing..." );
return 1;
}
/* write to file */
fprintf( FilePointer,
"Test Text to test file writing and reading. Variable = %d...",
Variable );
Variable = 18745;
/* write to file */
fprintf( FilePointer,
"\nNextLine: Variable = %d...",
Variable );
/* done, close file */
fclose( FilePointer );
/* now test it, by reading and diplaying it */
/* open file for reading*/
FilePointer = fopen( "C:\\test.txt", "r" );
/* check if file found*/
if( FilePointer == NULL )
{
printf( "Unable to open file for reading..." );
return 2;
}
/* while still chars from file unread */
while( ! feof( FilePointer ) )
{
/* read from file */
fgets( cBuffer, BUFFER_SIZE, FilePointer );
/* display line from file */
printf( "Line read from file was:\n[%s]\n", cBuffer );
}
/* close file */
fclose( FilePointer );
getch();
return 0;
}
how did u do the syntax highlighting nv?
I used the PHP tag. :p
I volunteered in the mod's forum to code another
highlighting for the CODE tag if i have access to the
PHP one, because it's colored, but not really C-like.
can't wait to use the results of that ! :p
VS.NET code is colored even when you cut and paste it into programs like notepad or email.
Sorry, correct syntax is not FilePointer = fopen( "C:\test.txt", "r" );
it is: FilePointer=fopen("C:\\test.txt","r");
Please not the double back slashes in order to avoid representing an escape character.
in C# you can use and '@' sign which is a trigger that allows you to use single backslashes in your paths.
Hm, I copied that code directly from my VC,
it should have been correct... at least I do
have a file named test.txt on my C:\...
Code:backslash test: double backslashes: \\
Lets see if the PHP-tag eats it...PHP Code:
backslash test: double backslashes: \\
Oh, WK, I don't think .NET code will be colored
outside of an editor that supports coloring.
They would have to write a new notepad to do
what you promised... However, the @ symbol
could come in really handy in some situations.
When you cut and paste it into notepad or Outlook express or other apps it is colored! It retains the color.
Not colored in notepad but perhaps XML notepad. It is colored when transfered to Outlook Express or MS Office, wordpad, etc.
while(true)
{
//create a new node used to store a record from the input file
newp = (node_t *) malloc (sizeof(node_t));
newp->linkp = NULL;
doesn't work here though....