Showing posts with label Strings. Show all posts

Write a program to pass a string to function that display the string on the screen

#include <stdio.h>

#include <conio.h>
#include <string.h>
char* display(char *string)
{
     int i=0;
     char ch;
     printf("%s", string);
}
main()
{
      char str[]="I Like C!";
      display(str);
      getch();
}

Get a string from user and convert it into upper case

#include <stdio.h>

#include <conio.h>
char* upper(char *word);
int main()
{
    char word[100];
    printf("Enter a string: ");
    gets(word);
    printf("\nThe uppercase equivalent is: %s\n",upper(word));
    getch();
}

char* upper(char *word)
{
    int i;
    for (i=0;i<strlen(word);i++) word[i]=(word[i]>96&&word[i]<123)?word[i]-32:word[i];
    return word;

}

Lenght of string by evaluating the element in the character array one by one. And use of strlen() function


#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
      int i;
      char ch;
      char str[]="This is my 1st assignment of 2nd smester.";
      i=0;
      while(ch!='.')
      {
                    ch=str[i];
                    i++;          
      }
      printf("size of array by eveluating: %d\n", i);
      printf("size of array by Function: %d\n", strlen(str));
      getch();
}