Angel Calderon Wednesday, April 01, 2009 Chapter 09 Self-Checks 9.1 2. printf starts from the non spaced character till it finds the null character ‘\0’. 9.2 // // // //
Name: Angel Calderon Date: Tuesday, March 03, 2009 Course: COP 1220 Chapter 7 Review Question 6
#include "stdafx.h" #include "conio.h" #include "string.h" 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. 2. 3. 4.
Yes Yes Yes Yes
9. Yes 10.