C Programming Tutorial - strcat and strcpy



1. how to convert a lower case letter to an upper case letter
#include<stdio.h>

int main() {
    char a = 'a';
    char b = 'F';
    char c = '7';
    
    printf ("%c \n", toupper(a) ) ; (function for this is toupper)
    printf ("%c \n", toupper(b) ) ; 
    printf ("%c \n", toupper(c) ) ; 
    
  return 0;
}

2.

#include<stdio.h>

#include<string.h>  (Contains bunch of cool built in string functions)



int main() {



char muffin[100](wee need to make sure bunch of space in it) = "Hey " ; 



strcat(muffin, "Thileban" );  (string can catinate, tag on end of the one string to the other) 

printf("%s \n", muffin);

    

  return 0;

}

3.

#include<stdio.h>

#include<string.h>



int main() {



char muffin[100] = "Hey " ; (we need to make sure it never pass 100)



strcat(muffin, "Thileban " ); 
strcat(muffin, "you " ); 
strcat(muffin, "smell! " ); 

printf("%s \n", muffin);

    

  return 0;

}

4.

#include<stdio.h>

#include<string.h>



int main() {



char muffin[100] = "Hey " ; 


strcat(muffin, "Thileban " ); 
strcat(muffin, "you " ); 
strcat(muffin, "smell! " ); 

printf("%s \n", muffin);

strcpy(muffin, "Thileban is Awesome!"); (String copy, replace one string with another, this over writes with the other) 
printf("%s \n", muffin);

  return 0;

}

Comments