rec3-2010 - Recitation 3 Help & Hints for Assignment 1...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Assignment 1 String Review String parsing [exercise] Including files in C Arrays of Pointers Using makeargv() from R&R p37 [exercise]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
String review Sequence of zero or more characters terminated by NULL (‘\0’). You must account for NULL character when allocating your strings. Example 1: O/P of the program below ? #include “string.h” char string[]=“Hello”; printf(“String length = %d\n”, strlen(string)); Example 2: What's wrong below ? char string[] = “Hello”; char *s = (char *)malloc(strlen(string)); strcpy(s,string);
Background image of page 2
Common string functions char *strcpy (const char *dest,const char *src) copies a string from one location to another int strcmp(const char *string1,const char *string2) compares two strings lexicographically size_t strlen(const char *); Finds the length of C String char *strerror(int errnum) returns the string representation of an error number e.g errno. char *strcat(char *dest, const char *src); appends the string src to dest char *strchr(const char *, int); locates a character in a string, searching from the beginning char *strpbrk(const char *s, const char *accept); finds the first occurrence of any character in accept in s char *strstr(const char *haystack, const
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

rec3-2010 - Recitation 3 Help & Hints for Assignment 1...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online