|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
extremely easy... string function
I just need to loop through a long string to analyze it.
I read a file into char massive; then I need to: read 41 bytes,,, trash them read 3 bytes compare them read until end of line loop until end of the variable. whats the string function I need |
|
#2
|
||||
|
||||
|
So basically you want to read in a line and pull out characters 41,42, and 43.
Code:
#define MASSIVE_SIZE 1024 // or whatever massive means here
char massive[MASSIVE_SIZE];
// code placed in a function to emphasize that massive probably does not belong on the stack.
void foo(FILE *fp)
{
char substring[4];
fgets(massive,MASSIVE_SIZE,fp);
strncpy(substring,&massive[41],3);
substring[3] = '\0'; // need to manually add the null-terminator
}
|
|
#3
|
|||
|
|||
|
massive
I was reading 41 characters, reading 3 characters comparing and updating a counter then reading to /n
with this method I was doing many reads in the loop. now I would like to read the whole file 21000000 bytes (massive) into a variable and then loop through it as above.. each line has 41 characters of junk 3 lines of info and the rest junk. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > extremely easy... string function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|