14 Replies - 269 Views - Last Post: 24 October 2011 - 07:16 PM Rate Topic: -----

#1 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

I need to lowercase an entire string

Posted 24 October 2011 - 02:50 PM

For the ease of matching, I feel the best way to do this is to make both strings lowercase. How would i accomplish this?
Is This A Good Question/Topic? 0
  • +

Replies To: I need to lowercase an entire string

#2 novacrazy  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 117
  • Joined: 01-March 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 03:04 PM

Try using the c function int tolower(int c); in a loop that makes the array lowercase.

tolower reference
Was This Post Helpful? 0
  • +
  • -

#3 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: I need to lowercase an entire string

Posted 24 October 2011 - 03:04 PM

cplusplus.com has an example of converting a string to all lower case.
Was This Post Helpful? 0
  • +
  • -

#4 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 03:24 PM

Damn, I was hoping for a way so that I could easily just them all lowercase instantly, because I need to do that because it's a requirement for my if statement. But for some reason when I use tolower, it doesn't work because it is not a pointer.

This is the code when I try to implement tolower.
#include <stdio.h>
#include <string.h>
/* #include <conio.h> */

char *mygetline(char *line, int size)
{
   if ( fgets(line, size, stdin) )
   {
      /* check for trailing '\n' */
      char *newline = strchr(line, '\n'); 
      if ( newline )
      {
         /* overwrite the '\n' with 
            a terminating null 
         */
         *newline =  '\0'; 
      }
   }
   return line;
}
 
int main(void)
{
  char text[1000] = "";
  char * pch;
  char * pbody;
  char words[100][100];
  char body[100][100];
  int numWords = 0;
  int numBody = 0;
  int i;
  /* pch = strtok (text," "); */

  fputs("Input Forbidden words: ", stdout);
  fflush(stdout);
  

  printf("forbidden words = \"%s\"\n", mygetline(text, sizeof text));

  /* Convert to words */
  for ( pch = strtok (text, " ") ;
        numWords < 100 && pch != NULL ;
        pch = strtok (NULL, " "), numWords++ )
        
  {
    strcpy( words[numWords], pch );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s ", words[i]), i++);
  printf("\n");
  
  
  fputs("Input body of text words: ", stdout);
  fflush(stdout);
  printf("Body of text = \"%s\"\n", mygetline(text, sizeof text));
  
  for ( pbody = strtok (text, " ") ;
        numWords < 100 && pbody != NULL ;
        pbody = strtok (NULL, " "), numBody++ )
  {
    strcpy( body[numBody], pbody );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s\n", body[i]), i++);
  /*for(i=0; i<sizeof(words); i++){
           if(strcmp(body[i], "") == 0){
                               printf("true\n");}
                               
           else{printf("false\n");}}*/
 /*trying to see if any words match*/
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[0]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[0], "\n")>0){
                                char* q = body[0];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[1]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[1], "\n")>0){
                                char* q = body[1];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[2]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[2], "\n")>0){
                                char* q = body[2];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                               
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[3]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[3], "\n")>0){
                                char* q = body[3];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[4]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[4], "\n")>0){
                                char* q = body[4];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[5]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[5], "\n")>0){
                                char* q = body[5];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[6]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[6], "\n")>0){
                                char* q = body[6];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[7]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[7], "\n")>0){
                                char* q = body[7];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[8]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[8], "\n")>0){
                                char* q = body[8];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[9]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[9], "\n")>0){
                                char* q = body[9];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[10]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[10], "\n")>0){
                                char* q = body[10];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[11]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[11], "\n")>0){
                                char* q = body[11];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[12]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[12], "\n")>0){
                                char* q = body[12];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[13]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[13], "\n")>0){
                                char* q = body[13];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[14]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[14], "\n")>0){
                                char* q = body[14];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[15]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[15], "\n")>0){
                                char* q = body[15];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[16]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[16], "\n")>0){
                                char* q = body[16];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[17]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[17], "\n")>0){
                                char* q = body[17];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[18]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[18], "\n")>0){
                                char* q = body[18];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(tolower(words[i]), tolower(body[19]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[19], "\n")>0){
                                char* q = body[19];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
 for(i=0; i<25; i++){printf("%s ", body[i]);}
  getch();

  return (0);
}




this is the code that works, but doesn't do waht I want.

#include <stdio.h>
#include <string.h>
/* #include <conio.h> */

char *mygetline(char *line, int size)
{
   if ( fgets(line, size, stdin) )
   {
      /* check for trailing '\n' */
      char *newline = strchr(line, '\n'); 
      if ( newline )
      {
         /* overwrite the '\n' with 
            a terminating null 
         */
         *newline =  '\0'; 
      }
   }
   return line;
}
 
int main(void)
{
  char text[1000] = "";
  char * pch;
  char * pbody;
  char words[100][100];
  char body[100][100];
  int numWords = 0;
  int numBody = 0;
  int i;
  /* pch = strtok (text," "); */

  fputs("Input Forbidden words: ", stdout);
  fflush(stdout);
  

  printf("forbidden words = \"%s\"\n", mygetline(text, sizeof text));

  /* Convert to words */
  for ( pch = strtok (text, " ") ;
        numWords < 100 && pch != NULL ;
        pch = strtok (NULL, " "), numWords++ )
        
  {
    strcpy( words[numWords], pch );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s ", words[i]), i++);
  printf("\n");
  
  
  fputs("Input body of text words: ", stdout);
  fflush(stdout);
  printf("Body of text = \"%s\"\n", mygetline(text, sizeof text));
  
  for ( pbody = strtok (text, " ") ;
        numWords < 100 && pbody != NULL ;
        pbody = strtok (NULL, " "), numBody++ )
  {
    strcpy( body[numBody], pbody );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s\n", body[i]), i++);
  /*for(i=0; i<sizeof(words); i++){
           if(strcmp(body[i], "") == 0){
                               printf("true\n");}
                               
           else{printf("false\n");}}*/
 /*trying to see if any words match*/
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[0])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[0], "\n")>0){
                                char* q = body[0];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[1])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[1], "\n")>0){
                                char* q = body[1];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[2])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[2], "\n")>0){
                                char* q = body[2];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                               
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[3])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[3], "\n")>0){
                                char* q = body[3];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[4])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[4], "\n")>0){
                                char* q = body[4];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[5])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[5], "\n")>0){
                                char* q = body[5];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[6])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[6], "\n")>0){
                                char* q = body[6];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[7])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[7], "\n")>0){
                                char* q = body[7];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[8])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[8], "\n")>0){
                                char* q = body[8];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[9])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[9], "\n")>0){
                                char* q = body[9];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[10])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[10], "\n")>0){
                                char* q = body[10];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[11])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[11], "\n")>0){
                                char* q = body[11];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[12])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[12], "\n")>0){
                                char* q = body[12];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[13])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[13], "\n")>0){
                                char* q = body[13];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[14])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[14], "\n")>0){
                                char* q = body[14];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[15])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[15], "\n")>0){
                                char* q = body[15];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[16])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[16], "\n")>0){
                                char* q = body[16];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[17])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[17], "\n")>0){
                                char* q = body[17];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[18])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[18], "\n")>0){
                                char* q = body[18];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(words[i], body[19])==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[19], "\n")>0){
                                char* q = body[19];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
 for(i=0; i<25; i++){printf("%s ", body[i]);}
  getch();

  return (0);
}


Was This Post Helpful? 0
  • +
  • -

#5 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 03:42 PM

I think I realized the problem again... Well first of all I am doing it completely wrong. I was doing tolower(body[i]), which attempts to lower the element in the array. However, the element in that array is a word, so that means i have to try and lower the element within that element. So that basically leads me to another question, how do I lower the individual letters of each word?
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: I need to lowercase an entire string

Posted 24 October 2011 - 03:46 PM

You could always wrap your strcmp() and the tolower() function inside a function that returns an int, the same as strcmp().

Jim
Was This Post Helpful? 0
  • +
  • -

#7 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 03:59 PM

I am not sure exactly how to do that, let alone make it efficient.
Was This Post Helpful? 0
  • +
  • -

#8 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 04:13 PM

I tried to make a function:

char lowercase(char* word){
     int i;
     for(i=0; i<25; i++){word[i]=tolower(word[i]);}
     return word;
     
     }


and it seems to work by itself, but for some reason when i try to implement it into my code, it does not work. As soon as it gets to the matchmaking part, it crashes.

I get this warning: [Warning] return makes integer from pointer without a cast


Here is my new code:

#include <stdio.h>
#include <string.h>
/* #include <conio.h> */

char lowercase(char* word){
     int i;
     for(i=0; i<25; i++){word[i]=tolower(word[i]);}
     return word;
     
     }

char *mygetline(char *line, int size)
{
   if ( fgets(line, size, stdin) )
   {
      /* check for trailing '\n' */
      char *newline = strchr(line, '\n'); 
      if ( newline )
      {
         /* overwrite the '\n' with 
            a terminating null 
         */
         *newline =  '\0'; 
      }
   }
   return line;
}
 
int main(void)
{
  char text[1000] = "";
  char * pch;
  char * pbody;
  char words[100][100];
  char body[100][100];
  int numWords = 0;
  int numBody = 0;
  int i;
  /* pch = strtok (text," "); */

  fputs("Input Forbidden words: ", stdout);
  fflush(stdout);
  

  printf("forbidden words = \"%s\"\n", mygetline(text, sizeof text));

  /* Convert to words */
  for ( pch = strtok (text, " ") ;
        numWords < 100 && pch != NULL ;
        pch = strtok (NULL, " "), numWords++ )
        
  {
    strcpy( words[numWords], pch );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s ", words[i]), i++);
  printf("\n");
  
  
  fputs("Input body of text words: ", stdout);
  fflush(stdout);
  printf("Body of text = \"%s\"\n", mygetline(text, sizeof text));
  
  for ( pbody = strtok (text, " ") ;
        numWords < 100 && pbody != NULL ;
        pbody = strtok (NULL, " "), numBody++ )
  {
    strcpy( body[numBody], pbody );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s\n", body[i]), i++);
  /*for(i=0; i<sizeof(words); i++){
           if(strcmp(body[i], "") == 0){
                               printf("true\n");}
                               
           else{printf("false\n");}}*/
  char c;         
  
 /*trying to see if any words match*/
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[0]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[0], "\n")>0){
                                char* q = body[0];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[1]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[1], "\n")>0){
                                char* q = body[1];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[2]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[2], "\n")>0){
                                char* q = body[2];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                               
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[3]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[3], "\n")>0){
                                char* q = body[3];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[4]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[4], "\n")>0){
                                char* q = body[4];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[5]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[5], "\n")>0){
                                char* q = body[5];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[6]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[6], "\n")>0){
                                char* q = body[6];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[7]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[7], "\n")>0){
                                char* q = body[7];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[8]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[8], "\n")>0){
                                char* q = body[8];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[9]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[9], "\n")>0){
                                char* q = body[9];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[10]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[10], "\n")>0){
                                char* q = body[10];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[11]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[11], "\n")>0){
                                char* q = body[11];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[12]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[12], "\n")>0){
                                char* q = body[12];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[13]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[13], "\n")>0){
                                char* q = body[13];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[14]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[14], "\n")>0){
                                char* q = body[14];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[15]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[15], "\n")>0){
                                char* q = body[15];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[16]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[16], "\n")>0){
                                char* q = body[16];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[17]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[17], "\n")>0){
                                char* q = body[17];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[18]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[18], "\n")>0){
                                char* q = body[18];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[19]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[19], "\n")>0){
                                char* q = body[19];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
 for(i=0; i<25; i++){printf("%s ", body[i]);}
  getch();

  return (0);
}


This post has been edited by bstfrmdamidaeast: 24 October 2011 - 04:19 PM

Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: I need to lowercase an entire string

Posted 24 October 2011 - 04:15 PM

You write a function where you pass your strings to be compared, along with the maximum size of these strings. First compare the string lengths, if they are different then return the proper value, check the documentation of strcmp(). If they are the same convert the strings to lower or upper case the compare the strings, return the value returned from strcmp() to the calling program. In the function before you change the case you may want to create local variables so you don't modify the actual variables.

Jim
Was This Post Helpful? 0
  • +
  • -

#10 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 04:35 PM

Could you please read my edits.
Was This Post Helpful? 0
  • +
  • -

#11 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: I need to lowercase an entire string

Posted 24 October 2011 - 04:43 PM

What edits? Please restate your current problem and post your current code. If you get compiler errors post the complete error messages exactly as they appear in your development environment.

Jim
Was This Post Helpful? 0
  • +
  • -

#12 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 05:05 PM

My problem as of right now is that when i pass the words through my function,
char lowercase(char *word){
     int i;
     for(i=0; i<25; i++){word[i]=tolower(word[i]);}
     return *word;
     
     }




I get this warning:[Warning] passing arg 1 of `strcmp' makes pointer from integer without a cast ."

When i try to run my program, it crashes when it reaches this part of the code, the part where i lowercase everything.

 for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[0]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[0], "\n")>0){
                                char* q = body[0];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }


Here is my code:

#include <stdio.h>
#include <string.h>
/* #include <conio.h> */

char lowercase(char *word){
     int i;
     for(i=0; i<25; i++){word[i]=tolower(word[i]);}
     return *word;
     
     }

char *mygetline(char *line, int size)
{
   if ( fgets(line, size, stdin) )
   {
      /* check for trailing '\n' */
      char *newline = strchr(line, '\n'); 
      if ( newline )
      {
         /* overwrite the '\n' with 
            a terminating null 
         */
         *newline =  '\0'; 
      }
   }
   return line;
}
 
int main(void)
{
  char text[1000] = "";
  char * pch;
  char * pbody;
  char words[100][100];
  char body[100][100];
  int numWords = 0;
  int numBody = 0;
  int i;
  /* pch = strtok (text," "); */

  fputs("Input Forbidden words: ", stdout);
  fflush(stdout);
  

  printf("forbidden words = \"%s\"\n", mygetline(text, sizeof text));

  /* Convert to words */
  for ( pch = strtok (text, " ") ;
        numWords < 100 && pch != NULL ;
        pch = strtok (NULL, " "), numWords++ )
        
  {
    strcpy( words[numWords], pch );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s ", words[i]), i++);
  printf("\n");
  
  
  fputs("Input body of text words: ", stdout);
  fflush(stdout);
  printf("Body of text = \"%s\"\n", mygetline(text, sizeof text));
  
  for ( pbody = strtok (text, " ") ;
        numWords < 100 && pbody != NULL ;
        pbody = strtok (NULL, " "), numBody++ )
  {
    strcpy( body[numBody], pbody );
  }

  /* print array of strings */
  for(i=0; i<25; printf("%s\n", body[i]), i++);
  /*for(i=0; i<sizeof(words); i++){
           if(strcmp(body[i], "") == 0){
                               printf("true\n");}
                               
           else{printf("false\n");}}*/
  char c;         
  
 /*trying to see if any words match*/
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[0]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[0], "\n")>0){
                                char* q = body[0];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[1]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[1], "\n")>0){
                                char* q = body[1];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[2]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[2], "\n")>0){
                                char* q = body[2];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                               
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[3]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[3], "\n")>0){
                                char* q = body[3];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[4]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[4], "\n")>0){
                                char* q = body[4];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[5]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[5], "\n")>0){
                                char* q = body[5];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[6]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[6], "\n")>0){
                                char* q = body[6];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[7]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[7], "\n")>0){
                                char* q = body[7];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[8]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[8], "\n")>0){
                                char* q = body[8];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[9]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[9], "\n")>0){
                                char* q = body[9];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[10]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[10], "\n")>0){
                                char* q = body[10];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[11]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[11], "\n")>0){
                                char* q = body[11];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[12]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[12], "\n")>0){
                                char* q = body[12];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[13]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[13], "\n")>0){
                                char* q = body[13];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[14]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[14], "\n")>0){
                                char* q = body[14];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
    for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[15]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[15], "\n")>0){
                                char* q = body[15];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[16]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[16], "\n")>0){
                                char* q = body[16];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[17]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[17], "\n")>0){
                                char* q = body[17];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[18]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[18], "\n")>0){
                                char* q = body[18];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
  for(i=0; i<25; i++){
           
           if(strcmp(lowercase(words[i]), lowercase(body[19]))==0 && strcmp(words[i], "\n") > 0){
                               if(strcmp(body[19], "\n")>0){
                                char* q = body[19];
                                while( *q != 0 ) { *q = 'X'; ++q; }
                                
                                }
                                }
                                
                                    
            
           
           }
           
 for(i=0; i<25; i++){printf("%s ", body[i]);}
  getch();

  return (0);
}


This post has been edited by bstfrmdamidaeast: 24 October 2011 - 05:06 PM

Was This Post Helpful? 0
  • +
  • -

#13 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: I need to lowercase an entire string

Posted 24 October 2011 - 05:30 PM

When I compile this code I get the following errors:

Quote

main.c||In function ‘lowercase’:|
main.c|8|error: implicit declaration of function ‘tolower’|
main.c||In function ‘main’:|
main.c|85|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|85|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|99|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|99|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|114|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|114|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|128|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|128|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|142|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|142|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|157|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|157|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|172|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|172|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|186|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|186|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|201|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|201|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|215|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|215|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|229|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|229|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|244|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|244|error: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast|
/usr/include/string.h|143|note: expected ‘const char *’ but argument is of type ‘char’|
main.c|258|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 2 warnings ===|


For the first message, you must include ctype.h to use tolower.
The next error is on line 85:

Quote

main.c|85|error: passing argument 1 of ‘strcmp’ makes pointer from integer without a cast|

           if(strcmp(lowercase(words[i]), lowercase(body[0]))==0 && strcmp(words[i], "\n") > 0){


And then lets look at the the lowercase function:
char lowercase(char *word){
     int i;
     for(i=0; i<25; i++){word[i]=tolower(word[i]);}
     return *word;

     }


What is the return type for this function? Is it a pointer? Hint no, it's a single character. Your function declaration should be:
char* lowercase(char *word)

And you should be returning a pointer:
return word;


After I made those changes and added the ctype.h include file the code compiles with only 1 warning:

Quote

main.c|80|warning: unused variable ‘c’|


In future when you get errors when compiling your code, post the complete error messages exactly as they appear in your development environment. These messages have important information embedded in them to facilitate locating and diagnosing the errors. One of the important pieces of information is the line number where the error is being detected.


Jim

This post has been edited by jimblumberg: 24 October 2011 - 05:31 PM

Was This Post Helpful? 0
  • +
  • -

#14 bstfrmdamidaeast  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 89
  • Joined: 18-September 11

Re: I need to lowercase an entire string

Posted 24 October 2011 - 06:18 PM

Wow that worked perfectly! Thank you so much, and sorry for all the trouble I have caused. I really do appreciate it!
Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: I need to lowercase an entire string

Posted 24 October 2011 - 07:16 PM

Also you should not use the "magic number" 25 in this function. Use the fact that a character string is terminated with '\0' to your advantage:
char* lowercase(char *word){
     int i = 0;
     while(word[i] != '\0')
     {
        word[i]=tolower(word[i]);
        ++i;
     }
     return word;
     
     }

This way this function should work of any sized "word".

Jim

This post has been edited by jimblumberg: 24 October 2011 - 07:17 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1