c strings n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
C Strings PowerPoint Presentation
Download Presentation
C Strings

Loading in 2 Seconds...

play fullscreen
1 / 6

C Strings - PowerPoint PPT Presentation


  • 180 Views
  • Uploaded on

C Strings. Systems Programming. Strings. Strings versus Single characters Pointers versus Arrays Accessing Array of Strings with Pointers. 2. Strings. Strings are arrays of characters terminated by ‘ \0 ’ (null). The \0 occupies one char in the array of characters. H. e. l. l. o.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'C Strings' - trilby


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
c strings

C Strings

Systems Programming

strings
Strings
  • Strings versus Single characters
  • Pointers versus Arrays
  • Accessing Array of Strings with Pointers

Systems Programming: Strings

2

strings1
Strings

Strings are arrays of characters terminated by ‘\0’ (null).

The \0 occupies one char in the array of characters.

H

e

l

l

o

\0

Systems Programming: Strings

3

character strings
Character Strings

W

char c = ‘W’; c

char *s = “George Bush”

char s2[] = “Hillary”

s2

H

i

l

l

a

r

y

\0

Systems Programming: Strings

character strings1
Character Strings

s2[0] = ‘B’;

s2[4] = ‘\0’;

S2

printf(“%s\n”, s2);

B

i

l

l

\0

r

y

\0

Systems Programming: Strings

an array of strings example
An Array of Strings Example

/* An Example of an Array of Strings accessed using a string pointer */

int main ()

{

int i,j;

char let = 'A';

char cray [3][10];

char *cptr[3];

for (j=0; j<3; j++)

cptr[j] = &cray [j][0];

for (j=0; j<3; j++)

{ let = let +1;

for (i=0; i<9; i++)

cray [j][i] = let + i;

cray [j][9] = '\0';

}

for (j=0; j<3; j++)

printf("j = %d, char = %s\n", j, cptr[j]);

return 0;

}

./charray

j = 0, char = BCDEFGHIJ

j = 1, char = CDEFGHIJK

j = 2, char = DEFGHIJKL

Systems Programming: Strings