Topic: Tabulation Problem


Author: bennania@ift.ulaval.ca (Abdelilah Bennani-khir)
Date: 1995/07/07
Raw View
I've one program whose job is to process specifics strings which contains tabulation characters. For example : the Input is
toto is dead
The program must return this result:
toto
is
dead
When I execute the program in visual C++, he can't recognize the tabulation . When I asked the help for c/c++ language, I found that the tabulation is not supported under windows.
The code program is :
#include  <stdio.h>
#include  <string.h>

char * find(char*,char);

main()
{
 char line[100];
 char *ptr1;
 char *ptr2;
 char *ptr3[100];
 int i=0;

 fgets(line, sizeof(line), stdin);
 line[strlen(line)-1] = '\0';
 ptr2 = line;
 while (find(ptr2,0x09)!= NULL)
 {
  ptr1 = find(ptr2,0x09);
  *ptr1 = '\0';
  ptr1++;
  ptr3[i] = ptr2;
  printf("word:%s\n",ptr3[i]);
  i++;
  ptr2 = ptr1;
 }
 ptr3[i] = ptr2;
 printf("word:%s\n",ptr3[i]);
 return(0);
}

char *find(char *string_ptr, char wrd)
{
 while (*string_ptr != 0x09)
 {
  if (*string_ptr == '\0')
  return (NULL);
  string_ptr++;
 }
 return (string_ptr);
}


When I replace 0x09(tabulation) by 0x20 (space) the program execute succefully.
Please, if you have any idea to resolve this problem send me your solution.
Thanks!

Bennani Abdelilah
E-Mail: bennania@ift.ulaval.ca