C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 13th, 2003, 01:41 PM
slam slam is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 3 slam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old June 13th, 2003, 02:07 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,836 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 6 h 59 m 13 sec
Reputation Power: 446
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
}

Reply With Quote
  #3  
Old June 13th, 2003, 02:38 PM
slam slam is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 3 slam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > extremely easy... string function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway