



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: INTRO TO SYSTEMS SOFTWARE; Subject: Computer Science; University: University of Pittsburgh; Term: Spring 2007;
Typology: Lab Reports
1 / 5
This page cannot be seen from the preview
Don't miss anything!




Listing 1 #include <stdio.h> #define NUM_ELEMS 7 int main() { int arr[NUM_ELEMS] = {5, 8, 10, 2, 9, 4, 1}; int *p, *pend; for (p=arr, pend=(p + NUM_ELEMS); p<pend; p++) printf("%d\n", *p); return 0; }
Listing 2 #include <stdio.h> #define NUM_ELEMS 7 int main() {
short int arr[NUM_ELEMS] = {5, 8, 10, 2, 9, 4, 1}; int *p, *pend; for (p=arr, pend=(p + NUM_ELEMS); p<pend; p++) printf("%d\n", *p); return 0; } Listing 3 #include <stdio.h> #define NUM_ELEMS 7 int main() { double arr[NUM_ELEMS] = {5.0, 8.0, 10.0, 2.0, 9.0, 4.0, 1.0}; float *p, *pend; for (p=arr, pend=(p + NUM_ELEMS); p<pend; p++) printf("%d\n", *p); return 0; }
#include <stdio.h> typedef struct{ int x; int y; }INTEGERS; void manipulateIntegers( INTEGERS ); void printIntegers( INTEGERS ); int main() { INTEGERS i; i.x = 2; i.y = 3; printIntegers( i ); manipulateIntegers( i ); printIntegers( i ); } void printIntegers( INTEGERS i ) (^1) By Mohammad Hammoud
STUDENT s[2]; char *arr[2][3]= { {"MHH1", "123", "pgh"}, {"MHH2", "456", "pgh"} }; enrollStudent(&s[0], arr[0]); enrollStudent(&s[1], arr[1]); printDatabase( s); } void printDatabase( const STUDENT s[] ) { printf( "NAME\tID\tADDRESS\n\n"); int i; for( i = 0; i < 2; i++) printf( "%s\t%s\t%s\n", s[i].name, s[i].id, s[i].address ); } void enrollStudent( STUDENT *s, char *data[]) { s->name = data[0]; s->id = data[1]; s->address = data[2]; }
Listing 4 #include <stdio.h> #include <string.h> int testPalindrome(const char string, int start, int end) { / write your code here */ } int main() { printf ("%d\n", testPalindrome("radar", 0, strlen("radar")-1)); printf ("%d\n", testPalindrome("saas", 0, strlen("saas")-1)); (^2) Modified from exercise 6.31, pg. 265 in the book
printf ("%d\n", testPalindrome("scifi", 0, strlen("scifi")-1)); return 0; } Listing 5 #include <stdio.h> #include <string.h> int testPalindromePtr(char *start, char end) { / write your code here */ } int main() { char *string; int strlength; string = "civic"; strlength = strlen(string); printf ("%d\n", testPalindromePtr( &string[0], &string[strlength-1] )); string = "saas"; strlength = strlen(string); printf ("%d\n", testPalindromePtr( &string[0], &string[strlength-1] )); string = "none"; strlength = strlen(string); printf ("%d\n", testPalindromePtr( &string[0], &string[strlength-1] )); return 0; }