1 / 14

STRING.H

STRING.H. C string functions! Gloria Szilasi. Strings in C . C-Style Strings are really arrays! Char string[50]; will declare a string for 49 letters. You are allowed to delete! Delete [] array ; They use pointer to! . Basic. printf (“My Name is”); // print a line

job
Download Presentation

STRING.H

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STRING.H C string functions! Gloria Szilasi

  2. Strings in C • C-Style Strings are really arrays! • Char string[50]; will declare a string for 49 letters. • You are allowed to delete! • Delete [] array; • They use pointer to!

  3. Basic • printf(“My Name is”); // print a line • scanf(“%s”,name);//reads in a STRING • %s for String • %d for Int • printf(“Your value is %d congratulations”,value); • Where %d is , value gets printed

  4. String Functions The nine most commonly used functions (and their parameters) in the string library are:

  5. String Functions • strcat - concatenate two strings • (Destination, source) • strncat - concatenate one string with part of another • (Destination, source, num) • Num=max number of characters to be appended • strchr - string scanning operation • (str, character) • Returns a pointer to first occurrence

  6. String Functions continue… • strcmp - compare two strings • (str1, str2) • if( strcmp(mystring, yourstring) == 0) //zero indicates both are equal • strcpy - copy a string • (destination, source) • strncpy - copy part of a string • (destination, source, num) • Num=max # char copied from source

  7. String Functions continue… • strlen - get string length • (string) • strncmp - compare parts of two strings • (st1,str2,num) • strrchr - string scanning operation • (str, character)

  8. strcpy

  9. strcat

  10. strncmp

  11. strchr

  12. practice • Write a program in C using the #include<string.h> function’s that does the following: • Ask the user 1ST to enter in their last name. • Then enter in their first name. • Then concatenate the two strings using strncat(); • When conceiting it does not add a space.How can you do this? • Tell the user’s name length. • Ask user if the name they entered is correct. • ( hint: use a loop and strcmp)

  13. If you have time…. • Check at what position a certain letter is in the array. • Example. My name is Gloria, and I want to know the position of the letter r. • Answer:4 • I just want to display my name as szilasiG. • So not print out my entire first name. • What function would I use?

  14. Help. • http://www.cprogramming.com/tutorial/c/lesson9.html • http://www.cplusplus.com/reference/clibrary/cstring/

More Related