Strings Flashcards

1
Q

When does null terminator need to be included in a string?

A

Using string functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

‘\0’

A

NULL Terminator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

strlen argument(s)

A

char *

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does strlen return?

A

Int; Index of first NULL Terminator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What should you do instead of

while (i < strlen(str)) {

}

A

while(str[i] != ‘\0’) {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Find length of string

A

strlen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

strcpy arguments

A

2 char *s; destination, source

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does strcpy return?

A

char *; pointer to destination

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Given strings a and b, what should you do instead of:

a = b;

A

strcpy(a, b);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Store word “Apple” into string str

A

char str[5+1];
strcpy(str, “Apple”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Joins two strings together in c.

A

strcat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

strcat arguments

A

2 char *s; destination and source

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does strcat return?

A

char *; destination

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Mnemonic way to think about strcpy

A

strcpy(a,b) is a = b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Mnemonic way to think about strcat

A

strcat(a,b) is a += b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Mnemonic way to think about strcmp

A

strcmp(a, b) is a - b

17
Q

What does strcmp(“a”, “A”) return?

A

Positive int

18
Q

What does strcmp(“A”, “a”) return?

A

Negative int

19
Q

What does strcmp(“z”, “A”) return?

A

Positive int

20
Q

What does strcmp(“A”, “z”) return?

A

Negative int

21
Q

What does strcmp(“a”, “z”) return?

A

Negative int

22
Q

What does strcmp(“z”, “a”) return?

A

Positive int

23
Q

What does strcmp(“a”, “aa”) return?

A

Negative int

24
Q

What does strcmp(“aa”, “a”) return?

A

Positive int

25
Q

fgets argument(s)

A

First: char *; destination
Second: int; size of char array
Third: File *; source; usually stdin

26
Q

Function that reads a full line up to and including newline characters.

A

fgets

27
Q

When using fgets, what happens if the input is larger than the expected size?

A

As much of the input is written as possible with room for the null terminator at the end

28
Q

How big should you make a char array to hold information from fgets?

A

MAX_LINE_SIZE + 2

29
Q

What string function returns the index of the first NULL terminator?

A

strlen