HIDE NAV

String Operations Assignment Hints Pt 1

Code to help you get started with the stringOps.c part of the strings and structs code assignment.

stringOpsHintsPt1.c


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

	char firstName[100];
	strcpy(firstName, "Geoffrey");

	char midName[100];
	strcpy(midName, "Rickets");

	char lastName[100];
	strcpy(lastName, "Montgummery");

	int fNameSize = strlen(firstName);
	printf("%s is %d characters long.\n", firstName, fNameSize);

	char midInitial = midName[0];
	printf("%s's middle initial is '%c'.\n", firstName, midInitial);

	char fNameCaps[100];
	strcpy(fNameCaps, firstName);
	for (int i = 0; i < strlen(firstName); i++) {
		if (fNameCaps[i] > 96 && fNameCaps[i] < 96+26) {
			fNameCaps[i] -= 32;
		}
	}
	printf("%s's first name in all caps: '%s'.\n", firstName, fNameCaps);

	// HINT: strcat could be used to assmble the full name.
	// HINT: printf is useful for assembling messages with strings for output.

	return 0;
}