C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 September 25th, 2012, 10:54 PM
crystal_moon crystal_moon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 2 crystal_moon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 58 sec
Reputation Power: 0
Help: extracting string from file

HI
I'm a newbie and don't have much knowledge in c and I'm stuck.
I need to extract a string saved in a file , get its length and then add extra character(like zero) as a padding till it reach some size.
I have been trying to do it like this but it is not complete, I don't know how to get it to work. can you please help me
Code:
 FILE *file = fopen( argv[1], "r" );

        if ( file == 0 )
        {
            printf( "Could not open file\n" );
        }
        else 
        {
            int x;
          
            while  ( ( x = fgetc( file ) ) != EOF )
            {
                printf( "%c", x );
            }
            fclose( file );

Thanks in advance.
Regards

Reply With Quote
  #2  
Old September 26th, 2012, 03:34 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
If you want to save the string for later, you need to get an array for it

Code:
char data[100]; /* enough space for a string with length up to 99 */


Also you need to put ecah character read from the file in there.

Have fun!

Reply With Quote
  #3  
Old September 27th, 2012, 06:33 PM
crystal_moon crystal_moon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 2 crystal_moon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 24 m 58 sec
Reputation Power: 0
Thank you very much.

regards

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help: extracting string from file

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap