read file from bottom
-
Standard header files should be included withh
<
and>
. eg.#include <stdio.h>
.Steve
Doesnt that just change the search scope for the file included? which will have little effect if it is increased scope maybe u wil lose 0.00000000001n.S in compile time. (realising that 85% of stats are made up on the spot) if it does have some esoteric effect that i have been lucky enough to avoid thus far please educate me.
-
I need to read a file from the bottom is it possible in c language ? The exact requirement is suppose having a file like ======================================== hi how are you exit 1 then you exit 1 and i can make this exit 0 =========================================== I need to read the file from bottom to search the last exit 1 and print the lines above it the output will be then you Can anybody help me ??
vineesh
vineeshV wrote:
Can anybody help me ?
Sure....how about picking the correct forum :|
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Doesnt that just change the search scope for the file included? which will have little effect if it is increased scope maybe u wil lose 0.00000000001n.S in compile time. (realising that 85% of stats are made up on the spot) if it does have some esoteric effect that i have been lucky enough to avoid thus far please educate me.
First off, it's good style. Secondly it effects the search paths used.
Steve
-
I need to read a file from the bottom is it possible in c language ? The exact requirement is suppose having a file like ======================================== hi how are you exit 1 then you exit 1 and i can make this exit 0 =========================================== I need to read the file from bottom to search the last exit 1 and print the lines above it the output will be then you Can anybody help me ??
vineesh
At the risk of sounding stupid, why don't you do it two phases: 1. Read the file into a datatable, adding an additional column to represent a line number 2. Sort the table by line number (desc) and loop through. Edward
Edward Steward edwardsteward@optusnet.com.au
-
I need to read a file from the bottom is it possible in c language ? The exact requirement is suppose having a file like ======================================== hi how are you exit 1 then you exit 1 and i can make this exit 0 =========================================== I need to read the file from bottom to search the last exit 1 and print the lines above it the output will be then you Can anybody help me ??
vineesh
//initialize streamreader StreamReader myStream = new StreamReader(@"c:\myfile.txt"); //read all the contents and store in string string WholeFileString=myStream.ReadToEnd(); //convert to array char []strArray = WholeFileString.ToCharArray(); //reverse the array Array.Reverse(strArray); //again convert to string string newStr = new string(strArray); //specify the split array (Note \r\n must be specified reverse becoz string is reverse char [] split = new char[2]; split[0] = '\n'; split[1] = '\r'; //receive the string array after spliting string [] Lines = newStr.Split(split); lines[0] = ; //last line of the file lines[lines.Length-1] = ; //first line of the file
Regards, Punithkumar
-
//initialize streamreader StreamReader myStream = new StreamReader(@"c:\myfile.txt"); //read all the contents and store in string string WholeFileString=myStream.ReadToEnd(); //convert to array char []strArray = WholeFileString.ToCharArray(); //reverse the array Array.Reverse(strArray); //again convert to string string newStr = new string(strArray); //specify the split array (Note \r\n must be specified reverse becoz string is reverse char [] split = new char[2]; split[0] = '\n'; split[1] = '\r'; //receive the string array after spliting string [] Lines = newStr.Split(split); lines[0] = ; //last line of the file lines[lines.Length-1] = ; //first line of the file
Regards, Punithkumar
C# is the new C i see
-
C# is the new C i see
-
#include "stdafx.h" #include "stdio.h" #include "stdlib.h" #include "string.h" #define MEANINGFULL_SIZE 256 #define DELIM "\nexit 1\n" #define FILE_DATA "hi\nhow are you\nexit 1\nthen\nyou\nexit 1\nand i can\nmake this\nexit 0\n" int _tmain(int argc, _TCHAR* argv[]) { char* filestr = (char*)malloc(MEANINGFULL_SIZE); char* Found = (char*)malloc(MEANINGFULL_SIZE); char* Current = {0}; memcpy(filestr,FILE_DATA,MEANINGFULL_SIZE-1); //pseudo readfile Current = strstr(filestr,DELIM); //Find Stuff memcpy(Found,Current+strlen(DELIM),strlen(Current));//copy what ever was found minus the delims Current = strstr(Found,DELIM);//find the next delims *Current = '\0'; //truncate the string printf("%s \n",Found);//publish the result while(1); return 0; } Hope this helps u ;P
modified on Tuesday, July 1, 2008 5:57 AM
-
killabyte wrote:
char* filestr = (char*)malloc(MEANINGFULL_SIZE);
Shouldn't soemthing be freed somewhere ?
-
At the risk of sounding stupid, why don't you do it two phases: 1. Read the file into a datatable, adding an additional column to represent a line number 2. Sort the table by line number (desc) and loop through. Edward
Edward Steward edwardsteward@optusnet.com.au