printf

void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng==pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;

      getch() ;

      transmit();
      slen -= leng;
  } while(slen>0);

}
In the above function,
regarding this command: printf("%*.*s\n", leng, leng, pF) ;
Ques: What this command do in this function? What *.* means?
bbtssAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
>>  leng==pE-pF

I guess you intend to do:

leng = pE - pF ;

Now, %*.*s will print out 'leng' number of characters from the starting of the pF.

e.g., if pF points to: "YourName" and leng = 5, then:

printf ( "%*.*s\n", leng, leng, pF ) ;

will print:

YourN

Sameway, writing:

printf ( "%*.*s\n", leng, leng - 1, pF ) ;

will print leng characters in total, leng - 1 characters from the string, and the remaining are filled with blanks. In fact, first the blanks are printed, and then the characters, like:

 Your

So, in:

printf ( "%*.*s\n", leng, leng, pF ) ;

The first leng refers to the total number of characters to be printed, the second leng refers to the number of characters to be printed from the string pointed to by pF (and in case this number is smaller, then first, blanks will be printed).

I hope you got it.

Mayank.
0
bbtssAuthor Commented:
thanks for ur reply.
but is there any way that i can assign a pointer to this segmented string other than directly printf it out?
like the message is Yourname
this function will printf Yourn if leng is 5.
how can i assign a pointer to this segmented message?
0
lowmakaCommented:
It looks like you are trying to "extract" from a space-delimited string and proccess(transmit) them one "element" at a time. The element string should be from pC+1 to pE in the following code:

==========================================
 char *pE, *pF, *pC;

 slen = strlen(pMessage) ;
 slen = slen > MAXLEN ? MAXLEN : slen ;

 pF = pMessage;
 pE = pF + slen - 1;
 pC = pE;

 do
 {
       while (*pC != ' ')
       {
        if (*pC == 0) break ;
        pC--;
       }

       leng = pE - pC;

     printf("%*.*s\n", leng, leng, pC+1);

     getch() ;

     transmit();

     --pC;
     pE = pC;
     slen -= (leng+1);

 } while(slen>0);
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
lowmakaCommented:
Don't worry, English is my second language, too and sorry to confuse you. I was trying to work into your programming logic. Have you tried "strtok"? Some example code for you, good luck to you.



/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] = "This is a sample string,just testing.";
  char * pch;
  printf ("Splitting string \"%s\" in tokens:\n",str);
  pch = strtok (str, " ");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, " ,.");
  }
  return 0;
}
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAXLEN 50
char *pMsgString = {"HDLC defines three different data .................................."};
void display(char *pMss)
{
 printf("%s",pMss);
 getch();
}
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;
      getch();
      display(??);
      slen -= leng;
  } while(slen>0);

}
void main(void)
{
split (pMsgString);
}

hm... i dun quite get what u mean... actually what i want to know is how i store the segmented message into a pointer so that when i call the function it would only display the segmented part.In simple terms, how can i declare a pointer and place it into the ?? part so that the display function will only display the segmented message?
Hopefully u ppl can understand my english becos i a not quite good in it.
0
bbtssAuthor Commented:
Wow i didnt know i was pasting so much time...
well strtok seems to be only able to terminate at a null term. in my case i am suppose to send the characters 50 by 50. so i doubt i can use that.
0
Mayank SAssociate Director - Product EngineeringCommented:
>> strtok seems to be only able to terminate at a null term

No, it'll terminate at whichever character you want. e.g., if you want it to terminate at a comma:

char str[] = "Eagles, Guns n' Roses, Aerosmith, Metallica" ;
char * p ;

p = strtok ( str, "," ) ;

while ( p != NULL )
{
  printf ( "%s\n", p ) ;
  p = strtok ( NULL, "," ) ;

} // end while

It'll print:

Eagles
<space>Guns n' Roses
<space>Aerosmith
<space>Metallica

Hope that helps!

Mayank.
 
0
Mayank SAssociate Director - Product EngineeringCommented:
If you want to store that segmented part in another 'pointer' (as you said), I'd say that you prefer to keep an array of strings and keep copying your segmented parts (substrings) as:

char str[] = "Eagles, Guns n' Roses, Aerosmith, Metallica" ;
char * p ;
char temp[10][80] ; // assuming 10 substrings
int count = 0 ;

p = strtok ( str, "," ) ;

while ( p != NULL )
{
  strcpy ( temp[count++], p ) ;
  p = strtok ( NULL, "," ) ;

} // end while

for ( int i = 0 ; i < count ; i ++ )
  printf ( "%s\n", temp[i] ) ; // end for


Hope that helps!

Mayank.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isprabuCommented:
You can try something like this:
Declare a local array variable inside the split function

     char buff[MAXLEN+1];

and then instead of printf use sprintf:

     sprintf(buff,"%*.*s\n", leng, leng, pF) ;
     display(buff);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.