Results 1 to 2 of 2

Thread: pointers and dynamic memory allocation.

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Posts
    5

    pointers and dynamic memory allocation.

    How can I read a line of text and spaces and replace each space in the line with 3 stars dynamically?

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Note: check the syntax - could have typos
    Code:
    FILE *in;
    char *buf,tmp[256],*s;
    char stars[512];
    int i;
    in=fopen("myfile","r");
    while(!feof(in)){
             *tmp=0x00;
             if(fgets(tmp,255,in)!=NULL){
                      memset(stars,0x00,512);
                      for(buf=tmp,s=stars;*buf;buf++)
                                if(*buf==0x20)
                                      for(i=0;i<3;i++) *s++='*';
                                else 
                                      *s++=*buf;
             // stars now has the spaces replaced with three *
            // do something with the string stars
             }
    }
    fclose(in);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width