AD1

Thursday, 2 February 2017

convert to uppercase

Write a function upper() that accepts a string and converts all its characters into uppercase characters 
as example upper("c programming")=C PROGRAMMING
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool is_upper(char x)
{
if((int)x>=65&&(int)x<=90)
{
return true;
}
return false;
}
char *upper(char *base)//passing array to a function that returns a pointer to char
{
while(*base!='\0')
{
if(is_upper(*base)||*base==' '){*base++;}
else{*base-=32;base++;}
}
return base;
}
int main()
{
char array[20]="hE l lO";
upper(array);
puts(array);
return 0;
}
view raw upper.c hosted with ❤ by GitHub


No comments:

Post a Comment