You are on page 1of 2

Angel Calderon

Wednesday, April 01, 2009


// Name: Angel Calderon
// Date: Tuesday, March 03, 2009
Chapter 09 Self-Checks
// Course: COP 1220
// Chapter 7 Review Question 6
9.1
#include "stdafx.h"
#include2. "conio.h"
printf starts from the non spaced character till it finds the null character ‘\0’.
#include "string.h"
9.2
char *trim_blanks(char *trimmed, const char *to_trim)
{
/*Find subscript of the first nonblank in to_trim*/
int first_nonblank = 0;
for(int x=0;x<=strlen(to_trim);x++)
{
if(to_trim[x] != ' ')
{ first_nonblank = x; break; }
}

/*Find subscript of last nonbalnk in to_trim*/


int last_nonblank = 0;
for(int x=0;x<=strlen(to_trim);x++)
{
if(to_trim[x] == '\0')
{ break; }
else if(to_trim[x] != ' ')
{ last_nonblank = x; }
}

/*Use strncpy to store trimmed string in trimmed*/


int next = 0;
for(int x = first_nonblank; x<= last_nonblank; x++)
{
strncpy(&trimmed[next], &to_trim[x], last_nonblank );
next+=1;
}
trimmed[next+1] = '\0';

return " ";


}
9.3

Strcat(tmp, press[7]) parameter 2 is not a string or address but a character.

9.4

Both

Chapter Review

1. Yes
2. Yes
3. Yes
4. Yes

9. Yes

10.

You might also like