finished lab6

This commit is contained in:
Ziad Arafat committed 2020-03-09 23:36:01 -06:00
1 parent 09ebcd701b
commit 8c3a80453f
6 files changed
+90 -21

No files matched your search

+7 -7
View File
@@ -1,21 +1,21 @@
all: lab6
lab6: textfunctions.o lab6.o
gcc -Werror -Wall -O0 textfunctions.o lab6.o -o lab6
# gcc -Werror -Wall -O3 textfunctions.o lab6.o -o lab6
# gcc -Werror -Wall -O0 textfunctions.o lab6.o -o lab6
gcc -Werror -Wall -O3 textfunctions.o lab6.o -o lab6
# gcc -Werror -Wall textfunctions.o lab6.o -o lab6
# gcc -Wall textfunctions.o lab6.o -o lab6
valgrind ./lab6
# valgrind ./lab6
lab6.o: lab6.c textfunctions.h
gcc -Werror -Wall -O0 -c lab6.c
# gcc -Werror -Wall -O0 -c lab6.c
# gcc -Werror -Wall -O3 -c lab6.c
# gcc -Werror -Wall -c lab6.c
gcc -Werror -Wall -c lab6.c
# gcc -Wall -c lab6.c
textfunctions.o: textfunctions.c textfunctions.h
gcc -Werror -Wall -O0 -c textfunctions.c
# gcc -Werror -Wall -O3 -c textfunctions.c
# gcc -Werror -Wall -O0 -c textfunctions.c
gcc -Werror -Wall -O3 -c textfunctions.c
# gcc -Werror -Wall -c textfunctions.c
# gcc -Wall -c textfunctions.c
BIN
View File
Binary file not shown.
+9 -2
View File
@@ -14,7 +14,7 @@
int main( void ) {
char line[80];
// int count;
int count = 1;
FILE *cfPtr;
@@ -23,8 +23,15 @@ int main( void ) {
} else {
fgets( line, 80, cfPtr );
while ( !feof( cfPtr ) ) {
printf( "Line Read: %s\n\n", line );
printf("Processing line #%d\n", count);
wordPrint(line);
removePunctuation(line);
wordPrint(line);
stringSort(line);
blockPrint(line);
fgets( line, 80, cfPtr );
count++;
printf("\n");
} // end while
fclose( cfPtr );
} // end else
+8 -4
View File
@@ -1,4 +1,8 @@
the quick brown fox jumped
over the lazy dog.
THE QUICK BROWN FOX
JUMPED OVER THE LAZY DOG
E
.... .... &&&&... .&. %^&*)////????
asdfasdf....asdfasdf....1233
asdf 1234 asdf 1234
12345
54321
238753
asdf
+65 -8
View File
@@ -9,20 +9,77 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
void blockPrint( const char *c ) {
for ( int i = 0; c[i] != '\0'; i++ ) {
printf( "%c", c[i] );
for ( int j = i; c[j] == c[j + 1]; j++ ) {
printf( "%c", c[j] );
i++;
} // end for
printf( "\n" );
} // end for
}
// void blockPrint ( const char *strPtr ){
// for(int i=0; i<strlen(strPtr); i++){
// printf("%c", *(strPtr+i));
// }
// }
void blockPrint(const char *c) {
void wordPrint( const char *c ) {
// creates a copy of the string that we can tokenize with strtok
char *copy = strdup( c );
char *tokenPtr = strtok( copy, " " );
// tokenizes the string and prints eachj subarray separated by a space.
while ( tokenPtr != NULL ) {
printf( "%s\n", tokenPtr );
tokenPtr = strtok( NULL, " " );
} // end while
}
void wordPrint(const char *c) {
void removePunctuation( char *c ) {
for ( int i = 0; c[i] != '\0'; i++ ) {
// if it's alphanumeric or a space we move all the remaining chars
// one space to the left.
if ( !isalnum( c[i] ) && !isspace( c[i] ) ) {
for ( int j = i; c[j] != '\0'; j++ ) {
c[j] = c[j + 1];
} // end for
i--; // move back to read the one we copied over it.
} // end if
} // end for
}
void removePunctuation(char *c) {
// same swap from lab5 to do the selection sort.
void swap( char *aPtr, char *bPtr ) {
float t = *aPtr;
*aPtr = *bPtr;
*bPtr = t;
}
void stringSort( char *c ) {
for ( int i = 0; c[i] != '\0'; i++ ) {
int space = isspace( c[i] );
// if it's a space delete it like we do in removePunctuation
if ( space ) {
for ( int j = i; c[j] != '\0'; j++ ) {
c[j] = c[j + 1];
} // end for
i--;
} // end if
} // end for
void stringSort(char *c) {
// Selectiopn sort from Lab5
for ( int i = 0; *( c + i ) != '\0'; i++ ) {
int min = i;
for ( int j = i; *( c + j ) != '\0'; j++ ) {
if ( *( c + j ) < *( c + min ) ) {
min = j;
} // end if
} // end for
if ( min != i ) {
swap( ( c + i ), ( c + min ) );
} // end if
} // end for
}
+1
View File
@@ -10,6 +10,7 @@
void blockPrint( const char *c );
void wordPrint( const char *c );
void removePunctuation( char *c );
void swap( char *aPtr, char *bPtr ); // for selection sort algorithm
void stringSort( char *c );
#endif