Ejemplo n.º 1
0
int main(int argc, char **argv) {
    // strdup makes a newly allocated (malloced) copy of a string
    char *orig = strdup("the internet is a series of tubes");
    char *copy = strdup(orig);
 
    /* ********************************** */
    /*    test of whitespace removal      */
    /* ********************************** */
    printf("remove whitespace: before <%s>", orig);
    printf(" and after <%s>\n", removewhitespace(copy));
 
    free(copy);                    // free modified copy
    copy = strdup(orig);           // make new copy
 
    /* ********************************** */
    /*  c to pascal and back to c tests   */
    /* ********************************** */
    char *pascalstr = c2pascal(copy);
    printf("made pascal string out of %s; orig strlen was %d and pascal strlen is %d\n", orig, (int)strlen(orig), (int)pascalstr[0]);
    char *cstr = pascal2c(pascalstr);
    printf("converted pascal string back to c.  orig: <%s> reconversion: <%s>\n", orig, cstr);
    free(copy);
 
    return 0;
}
Ejemplo n.º 2
0
int
main(int argc, char **argv) {
    char s1[] = "  the \tinternet is a series of tubes  ";
    char s2[] = "   \t\n";
    char s3[] = "  the \tinternet is not a series of tubes  ";
    char s4[] = "   \t\n";
    char s5[] = "8";
    
    removewhitespace(s1);
    removewhitespace(s2);
    printf("Remove whitespace - s1: %s\n", s1);
    printf("Remove whitespace - s2: %s\n", s2);

    printtokens(tokenify(s3));
    printtokens(tokenify(s4));
    printtokens(tokenify(s5));

    return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
   // strdup makes a newly allocated (malloced) copy of a string
   char *orig = strdup("the internet is a series of tubes");
   char *copy = strdup(orig);

   /* ********************************** */
   /*    test of whitespace removal      */
   /* ********************************** */
   printf("remove whitespace: before <%s> after <%s>\n", orig, removewhitespace(copy));

   free(copy);                    // free modified copy
   copy = strdup(orig);           // make new copy


   /* ********************************** */
   /*  c to pascal and back to c tests   */
   /* ********************************** */
   char *pascalstr = c2pascal(copy);
   printf("made pascal string out of %s; orig strlen was %d and pascal strlen is %d\n", orig, (int)strlen(orig), (int)pascalstr[0]);
   char *cstr = pascal2c(pascalstr);
   printf("converted pascal string back to c.  orig: <%s> reconversion: <%s>\n", orig, cstr);
   free(copy);



   /* ********************************** */
   /*          tokenify test             */
   /* ********************************** */
   copy = strdup(orig);
   char **x = tokenify(copy);
   int i = 0;
   printf("tokenified <%s>.  next output should show each token on a separate line.\n", orig);
   while (x[i]) {
       printf("\t<%s>\n", x[i]);
       i++;
   }

   return 0;
}