Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Checkpoint 6 Terminal Code ##
- student@student64:~$ ls
- cnlabs Documents Music Public Videos
- Desktop Downloads Pictures Templates
- student@student64:~$ cd ~/cnlabs/workshop02
- student@student64:~/cnlabs/workshop02$ make task1
- cc task1.c -o task1
- student@student64:~/cnlabs/workshop02$ ./task1
- Please enter some input: reee
- Your input was: reee
- student@student64:~/cnlabs/workshop02$ ./task1 <OperatingSystem.txt
- Please enter some input: Your input was: An operating system is a layer of sophisticated software that manages hardware resources and provides a common interface for user programs. Popular desktop operating systems include:
- - Windows
- - macOS
- - Linux
- student@student64:~/cnlabs/workshop02$ make task1
- cc task1.c -o task1
- student@student64:~/cnlabs/workshop02$ ./task1 <OperatingSystem.txt
- An operating system is a layer of sophisticated software that manages hardware resources and provides a common interface for user programs. Popular desktop operating systems include:
- - Windows
- - macOS
- - Linux
- student@student64:~/cnlabs/workshop02$
- ## Checkpoint 6 task1.c code ##
- #include <stdio.h>
- int main() {
- int nextChar;
- nextChar = getchar();
- while (nextChar != EOF){
- putchar(nextChar);
- nextChar = getchar();
- }
- return 0;
- }
- ## Checkpoint 7 Terminal window ## NOTE: This was a messy one, sorry for the length of things.
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:11:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(2);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 this is a test
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:10:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(2);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:10:7: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
- nanosleep(2);
- ^~~~~~~~~
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:12:7: warning: implicit declaration of function ‘uleep’ [-Wimplicit-function-declaration]
- uleep(useconds_t 2);
- ^~~~~
- task2.c:12:13: error: ‘useconds_t’ undeclared (first use in this function)
- uleep(useconds_t 2);
- ^~~~~~~~~~
- task2.c:12:13: note: each undeclared identifier is reported only once for each function it appears in
- task2.c:12:24: error: expected ‘)’ before numeric constant
- uleep(useconds_t 2);
- ^
- makefile:4: recipe for target 'task2' failed
- make: *** [task2] Error 1
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:12:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(2);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:13:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(2);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 testing
- student@student64:~/cnlabs/workshop02$ ./task2 hello hello
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:14:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(usecs);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 hello hello
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:6:15: warning: unused variable ‘usecs’ [-Wunused-variable]
- unsigned int usecs = 2;
- ^~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 hello hello
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:6:15: warning: unused variable ‘usecs’ [-Wunused-variable]
- unsigned int usecs = 2;
- ^~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 hello hello
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task2 hello hello
- student@student64:~/cnlabs/workshop02$ ./task1 hello hello
- student@student64:~/cnlabs/workshop02$ ./task1 hello hello
- hello
- hello
- student@student64:~/cnlabs/workshop02$ make task2
- makefile:4: warning: overriding recipe for target 'hello'
- makefile:2: warning: ignoring old recipe for target 'hello'
- cc task2.c -o task2
- student@student64:~/cnlabs/workshop02$ make task2
- make: 'task2' is up to date.
- student@student64:~/cnlabs/workshop02$ ./task2
- hello hello how are you
- hello hello how are you
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:12:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(2000);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 <OperatingSystem.txt
- An operating system is a layer of sophisticated software that manages hardware resources and provides a common interface for user programs. Popular desktop operating systems include:
- - Windows
- - macOS
- - Linux
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:13:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(usecs);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 <OperatingSystem.txt
- An operating system is a layer of sophisticated software that manages hardware resources and provides a common interface for user programs. Popular desktop operating systems include:
- - Windows
- - macOS
- - Linux
- student@student64:~/cnlabs/workshop02$ make task2
- gcc task2.c -o task2 -std=c99 -Wall
- task2.c: In function ‘main’:
- task2.c:13:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(usecs);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task2 <OperatingSystem.txt
- An operating system is a layer of sophisticated software that manages hardware resources and provides a common interface for user programs. Popular desktop operating systems include:
- - Windows
- - macOS
- - Linux
- student@student64:~/cnlabs/workshop02$ ^C
- student@student64:~/cnlabs/workshop02$
- ## Checkpoint 7 task2.c ##
- #include <stdio.h>
- #include <unistd.h>
- int main() {
- int nextChar;
- unsigned int usecs = 20000;
- nextChar = getchar();
- while (nextChar != EOF){
- if (nextChar == ' '){
- fflush (stdout);
- usleep(usecs);
- }
- putchar(nextChar);
- nextChar = getchar();
- }
- return 0;
- }
- ## Checkpoint 8 task3.c ##
- student@student64:~/cnlabs/workshop02$ make task3
- gcc task3.c -o task3 -std=c99 -Wall
- task3.c: In function ‘main’:
- task3.c:14:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(usecs);
- ^~~~~~
- task3.c:15:17: warning: missing terminating ' character
- putchar('\n')'
- ^
- task3.c:15:17: error: missing terminating ' character
- task3.c:16:3: error: expected ‘;’ before ‘}’ token
- }
- ^
- makefile:6: recipe for target 'task3' failed
- make: *** [task3] Error 1
- student@student64:~/cnlabs/workshop02$ make task3
- gcc task3.c -o task3 -std=c99 -Wall
- task3.c: In function ‘main’:
- task3.c:14:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(usecs);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task3 <OperatingSystem.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- Linuxstudent@student64:~/cnlabs/workshop02$ ./task3 <OperatingSystem.txt >Words.txt
- student@student64:~/cnlabs/workshop02$ cat Words.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- student@student64:~/cnlabs/workshop02$
- ## CHECKPOINT 8 task3.c ##
- #include <stdio.h>
- #include <unistd.h>
- #include <ctype.h>
- int main() {
- int nextChar;
- unsigned int usecs = 20000;
- nextChar = getchar();
- while (nextChar != EOF){
- if (nextChar == ' '){
- fflush (stdout);
- usleep(usecs);
- putchar('\n');
- }
- if (isalpha(nextChar)){
- putchar(nextChar);
- }
- nextChar = getchar();
- }
- return 0;
- }
- ## checkpoint 9 terminal code (note: this is another messy one sorry) ##
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- task4.c: In function ‘charCheck’:
- task4.c:38:2: warning: no return statement in function returning non-void [-Wreturn-type]
- }
- ^
- task4.c: In function ‘main’:
- task4.c:43:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(usecs);
- ^~~~~~
- task4.c:55:9: error: ‘wordCount’ undeclared (first use in this function)
- printf(wordCount + "words");
- ^~~~~~~~~
- task4.c:55:9: note: each undeclared identifier is reported only once for each function it appears in
- task4.c:56:9: error: ‘characterCount’ undeclared (first use in this function)
- printf(characterCount + "characters");
- ^~~~~~~~~~~~~~
- At top level:
- task4.c:17:6: warning: ‘charCheck’ defined but not used [-Wunused-function]
- int charCheck(int c){
- ^~~~~~~~~
- makefile:8: recipe for target 'task4' failed
- make: *** [task4] Error 1
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- task4.c: In function ‘charCheck’:
- task4.c:48:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
- usleep(usecs);
- ^~~~~~
- task4.c:61:9: error: ‘characterCount’ undeclared (first use in this function)
- printf(characterCount + "characters");
- ^~~~~~~~~~~~~~
- task4.c:61:9: note: each undeclared identifier is reported only once for each function it appears in
- task4.c: In function ‘main’:
- task4.c:67:1: error: expected declaration or statement at end of input
- }
- ^
- At top level:
- task4.c:18:6: warning: ‘charCheck’ defined but not used [-Wunused-function]
- int charCheck(int c){
- ^~~~~~~~~
- makefile:8: recipe for target 'task4' failed
- make: *** [task4] Error 1
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- task4.c: In function ‘main’:
- task4.c:68:1: error: expected declaration or statement at end of input
- }
- ^
- At top level:
- task4.c:18:6: warning: ‘charCheck’ defined but not used [-Wunused-function]
- int charCheck(int c){
- ^~~~~~~~~
- makefile:8: recipe for target 'task4' failed
- make: *** [task4] Error 1
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- task4.c: In function ‘charCheck’:
- task4.c:43:2: warning: no return statement in function returning non-void [-Wreturn-type]
- }
- ^
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- LinuxsFJ
- �x
- �$asestudent@student64:~/cnlabs/workshop02$ ./task4 <Operatingmake task4
- gcc task4.c -o task4 -std=c99 -Wall
- task4.c: In function ‘main’:
- task4.c:60:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(lineCount, " lines");
- ^~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:61:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(wordCount, " words");
- ^~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:62:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(charCount, " characters");
- ^~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:63:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(vowelCount, " vowels");
- ^~~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:64:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(lowerCount, " lowercase");
- ^~~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:65:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(upperCount, " uppercase");
- ^~~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- task4.c: In function ‘main’:
- task4.c:60:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(lineCount);
- ^~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:61:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(wordCount);
- ^~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:62:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(charCount);
- ^~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:63:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(vowelCount);
- ^~~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:64:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(lowerCount);
- ^~~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:65:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(upperCount);
- ^~~~~~~~~~
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- task4.c: In function ‘main’:
- task4.c:60:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf((char)lineCount);
- ^
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:61:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf((char)wordCount);
- ^
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:62:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf((char)charCount);
- ^
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:63:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf((char)vowelCount);
- ^
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:64:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf((char)lowerCount);
- ^
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task4.c:65:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf((char)upperCount);
- ^
- In file included from task4.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- Linux4 lines209 words172 characters209 vowels166 lowercase6 uppercasestudent@student64:~/cnlabs/workshop02$ make task4
- gcc task4.c -o task4 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- Linux
- 4 lines
- 209 words
- 172 characters
- 209 vowels
- 166 lowercase
- 6 uppercasestudent@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txmake task4
- gcc task4.c -o task4 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- Linux
- 4 lines
- 32 words
- 172 characters
- 209 vowels
- 166 lowercase
- 6 uppercasestudent@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txmake task4
- gcc task4.c -o task4 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- Linux
- 4 lines
- 32 words
- 209 characters
- 209 vowels
- 166 lowercase
- 6 uppercasestudent@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txmake task4
- gcc task4.c -o task4 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
- An
- operating
- system
- is
- a
- layer
- of
- sophisticated
- software
- that
- manages
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- Linux
- 4 lines
- 32 words
- 209 characters
- 65 vowels
- 166 lowercase
- 6 uppercase
- student@student64:~/cnlabs/workshop02$
- ## checkpoint 9 task4.c code ##
- #include <stdio.h>
- #include <unistd.h>
- #include <ctype.h>
- int main() {
- int nextChar;
- int lineCount = 0;
- int wordCount = 0;
- int charCount = 0;
- int vowelCount = 0;
- int upperCount = 0;
- int lowerCount = 0;
- //unsigned int usecs = 20000;
- nextChar = getchar();
- int charCheck(int c){
- if (c == '\n'){
- lineCount += 1;
- }
- if (isspace(c)){
- wordCount += 1;
- }
- if (isalpha(c)){
- //charCount += 1;
- }
- if (tolower(c) == 'a' || tolower(c) == 'e' || tolower(c) == 'i' || tolower(c) == 'o' || tolower(c) == 'u'){
- vowelCount += 1;
- }
- if (islower(c)){
- lowerCount += 1;
- }
- if (isupper(c)){
- upperCount += 1;
- }
- return 0;
- }
- while (nextChar != EOF){
- charCheck(nextChar);
- charCount += 1;
- if (nextChar == ' '){
- fflush (stdout);
- //usleep(usecs);
- putchar('\n');
- }
- if (isalpha(nextChar)){
- putchar(nextChar);
- }
- nextChar = getchar();
- }
- printf("\n%d lines", lineCount);
- printf("\n%d words", wordCount);
- printf("\n%d characters", charCount);
- printf("\n%d vowels", vowelCount);
- printf("\n%d lowercase", lowerCount);
- printf("\n%d uppercase\n", upperCount);
- return 0;
- }
- ## Checkpoint 10 terminal code ##
- hardware
- resources
- and
- provides
- a
- common
- interface
- for
- user
- programs
- Popular
- desktop
- operating
- systems
- include
- Windows
- macOS
- Linux
- 4 lines
- 32 words
- 209 characters
- 65 vowels
- 166 lowercase
- 6 uppercase
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:18:10: warning: implicit declaration of function ‘getChar’ [-Wimplicit-function-declaration]
- int c = getChar();
- ^~~~~~~
- task5.c:26:7: error: ‘nextChar’ undeclared (first use in this function)
- if (nextChar != '\n'){
- ^~~~~~~~
- task5.c:26:7: note: each undeclared identifier is reported only once for each function it appears in
- task5.c:29:8: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
- if (strlen(currentWord) > longestWordSize){
- ^~~~~~
- task5.c:29:8: warning: incompatible implicit declaration of built-in function ‘strlen’
- task5.c:29:8: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:26:7: error: ‘nextChar’ undeclared (first use in this function)
- if (nextChar != '\n'){
- ^~~~~~~~
- task5.c:26:7: note: each undeclared identifier is reported only once for each function it appears in
- task5.c:29:8: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
- if (strlen(currentWord) > longestWordSize){
- ^~~~~~
- task5.c:29:8: warning: incompatible implicit declaration of built-in function ‘strlen’
- task5.c:29:8: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:8: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
- if (strlen(currentWord) > longestWordSize){
- ^~~~~~
- task5.c:29:8: warning: incompatible implicit declaration of built-in function ‘strlen’
- task5.c:29:8: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:34:49: error: expected ‘;’ before ‘)’ token
- copy (currentWord, longestWord, arrayLength));
- ^
- task5.c:34:49: error: expected statement before ‘)’ token
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task 5 <Words.txt
- bash: ./task: No such file or directory
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- test
- what
- is
- going
- on
- I
- hate
- this
- I
- wish
- I
- didn't
- have
- to
- write
- this
- aaaaaaa
- ^C
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- n
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- AnnoperatingsystemisalayerofsophisticatedsoftwarethatmanageshardwareresourcesandprovidesacommoninterfaceforuserprogramsPopulardesktopoperatingsystemsincludeWindowsmacOSLinux
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- I found a new line!nI found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!I found a new line!
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:36:10: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(arrayLength);
- ^~~~~~~~~~~
- In file included from task5.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- narray length is 50ngarray length is 50marray length is 50sarray length is 50aarray length is 50rarray length is 50farray length is 50darray length is 50earray length is 50tarray length is 50sarray length is 50earray length is 50sarray length is 50darray length is 50sarray length is 50aarray length is 50narray length is 50earray length is 50rarray length is 50rarray length is 50sarray length is 50rarray length is 50parray length is 50garray length is 50sarray length is 50earray length is 50sarray length is 50Sarray length is 50
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- nngmsarfdetsesdsanerrsrpgsesS
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Current word is nnCurrent word is gCurrent word is mCurrent word is sCurrent word is aCurrent word is rCurrent word is fCurrent word is dCurrent word is eCurrent word is tCurrent word is sCurrent word is eCurrent word is sCurrent word is dCurrent word is sCurrent word is aCurrent word is nCurrent word is eCurrent word is rCurrent word is rCurrent word is sCurrent word is rCurrent word is pCurrent word is gCurrent word is sCurrent word is eCurrent word is sCurrent word is S
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:31:4: warning: implicit declaration of function ‘strncat’ [-Wimplicit-function-declaration]
- strncat(currentWord, &c, 1);
- ^~~~~~~
- task5.c:31:4: warning: incompatible implicit declaration of built-in function ‘strncat’
- task5.c:31:4: note: include ‘<string.h>’ or provide a declaration of ‘strncat’
- task5.c:31:25: warning: passing argument 2 of ‘strncat’ from incompatible pointer type [-Wincompatible-pointer-types]
- strncat(currentWord, &c, 1);
- ^
- task5.c:31:25: note: expected ‘const char *’ but argument is of type ‘int *’
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:32:25: warning: passing argument 2 of ‘strncat’ from incompatible pointer type [-Wincompatible-pointer-types]
- strncat(currentWord, &c, 1);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:136:14: note: expected ‘const char * restrict’ but argument is of type ‘int *’
- extern char *strncat (char *__restrict __dest, const char *__restrict __src,
- ^~~~~~~
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:32:25: warning: passing argument 2 of ‘strncat’ makes pointer from integer without a cast [-Wint-conversion]
- strncat(currentWord, c, 1);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:136:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern char *strncat (char *__restrict __dest, const char *__restrict __src,
- ^~~~~~~
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Current word is nnCurrent word is gCurrent word is mCurrent word is sCurrent word is aCurrent word is rCurrent word is fCurrent word is dCurrent word is eCurrent word is tCurrent word is sCurrent word is eCurrent word is sCurrent word is dCurrent word is sCurrent word is aCurrent word is nCurrent word is eCurrent word is rCurrent word is rCurrent word is sCurrent word is rCurrent word is pCurrent word is gCurrent word is sCurrent word is eCurrent word is sCurrent word is S
- n is the longest word
- it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:31:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- strcat(currentWord,c);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Segmentation fault
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:31:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- strcat(currentWord,(char)c);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:31:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- strcat(currentWord,c);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:23: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
- strcat(currentWord,itoa(c));
- ^~~~
- task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- task5.c:32:3: error: ‘arrayLength’ undeclared (first use in this function)
- arrayLength = sizeof(currentWord) / sizeof(currentWord[0]);
- ^~~~~~~~~~~
- task5.c:32:3: note: each undeclared identifier is reported only once for each function it appears in
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:23: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
- strcat(currentWord,itoa(c));
- ^~~~
- task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- /tmp/ccG5cNMy.o: In function `main':
- task5.c:(.text+0x175): undefined reference to `itoa'
- collect2: error: ld returned 1 exit status
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
- strcat(currentWord,(char *)c);
- ^
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:4: error: too many arguments to function ‘strcat’
- strcat(currentWord,&c,1);
- ^~~~~~
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: declared here
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Current word is A�l��n�l��Current word is A�l��n�l��o�l��p�l��e�l��r�l��a�l��t�l��i�l��n�l��g�l��Current word is �l��g�l��o�l��p�l��e�l��r�l��a�l��t�l��i�l��n�l��g�l��s�l��y�l��s�l��t�l��e�l��m�l��
- Segmentation fault
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Current word is A0�J��Current word is A0�J��n0�J��Current word is A0�J��n0�J��o0�J��Current word is A0�J��n0�J��o0�J��p0�J��Current word is A0�J��n0�J��o0�J��p0�J��e0�J��Current word is A0�J��n0�J��o0�J��p0�J��e0�J��r0�J��Current word is A0�J��n0�J��o0�J��p0�J��e0�J��r0�J��a0�J��Current word is A0�J��n0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��Current word is A0�J��n0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��Current word is A0�J��n0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��Current word is A0�J��n0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��g0�J��Current word is 0�J��g0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��g0�J��s0�J��Current word is 0�J��g0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��g0�J��s0�J��y0�J��Current word is 0�J��g0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��g0�J��s0�J��y0�J��s0�J��Current word is 0�J��g0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��g0�J��s0�J��y0�J��s0�J��t0�J��Current word is 0�J��g0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��g0�J��s0�J��y0�J��s0�J��t0�J��e0�J��Current word is 0�J��g0�J��o0�J��p0�J��e0�J��r0�J��a0�J��t0�J��i0�J��n0�J��g0�J��s0�J��y0�J��s0�J��t0�J��e0�J��m0�J��Current word is 0�J��g0�J��s0�J��y0�J��s0�J��t0�J��e0�J��m0�J��
- Segmentation fault
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:19:14: error: invalid initializer
- char c[2] = getchar();
- ^~~~~~~
- task5.c:27:11: warning: comparison between pointer and integer
- while (c != EOF && i < max_word_len-1) {
- ^~
- task5.c:28:9: warning: comparison between pointer and integer
- if (c != '\n'){
- ^~
- task5.c:40:5: error: assignment to expression with array type
- c = getchar();
- ^
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:22:2: error: variable-sized object may not be initialized
- char currentWord[max_word_len] = '\0';
- ^~~~
- task5.c:23:2: error: variable-sized object may not be initialized
- char longestWord[max_word_len] = '\0';
- ^~~~
- task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- strcat(currentWord,c);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- strcat(currentWord,c);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:11: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(c);
- ^
- In file included from task5.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- task5.c:30:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
- strcat(currentWord,c);
- ^
- In file included from task5.c:4:0:
- /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern char *strcat (char *__restrict __dest, const char *__restrict __src)
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Segmentation fault
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:11: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
- printf(c);
- ^
- In file included from task5.c:1:0:
- /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
- extern int printf (const char *__restrict __format, ...);
- ^~~~~~
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:13: error: expected expression before ‘)’ token
- printf(c*);
- ^
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:13: error: expected expression before ‘)’ token
- printf(c&);
- ^
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- task5.c: In function ‘main’:
- task5.c:29:16: error: expected expression before ‘)’ token
- printf("",c&);
- ^
- makefile:10: recipe for target 'task5' failed
- make: *** [task5] Error 1
- student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Current word is ACurrent word is nCurrent word is oCurrent word is pCurrent word is eCurrent word is rCurrent word is aCurrent word is tCurrent word is iCurrent word is nCurrent word is gCurrent word is sCurrent word is yCurrent word is sCurrent word is tCurrent word is eCurrent word is mCurrent word is iCurrent word is sCurrent word is aCurrent word is lCurrent word is aCurrent word is yCurrent word is eCurrent word is rCurrent word is oCurrent word is fCurrent word is sCurrent word is oCurrent word is pCurrent word is hCurrent word is iCurrent word is sCurrent word is tCurrent word is iCurrent word is cCurrent word is aCurrent word is tCurrent word is eCurrent word is dCurrent word is sCurrent word is oCurrent word is fCurrent word is tCurrent word is wCurrent word is aCurrent word is rCurrent word is eCurrent word is tCurrent word is hCurrent word is aCurrent word is tCurrent word is mCurrent word is aCurrent word is nCurrent word is aCurrent word is gCurrent word is eCurrent word is sCurrent word is hCurrent word is aCurrent word is rCurrent word is dCurrent word is wCurrent word is aCurrent word is rCurrent word is eCurrent word is rCurrent word is eCurrent word is sCurrent word is oCurrent word is uCurrent word is rCurrent word is cCurrent word is eCurrent word is sCurrent word is aCurrent word is nCurrent word is dCurrent word is pCurrent word is rCurrent word is oCurrent word is vCurrent word is iCurrent word is dCurrent word is eCurrent word is sCurrent word is aCurrent word is cCurrent word is oCurrent word is mCurrent word is mCurrent word is oCurrent word is nCurrent word is iCurrent word is nCurrent word is tCurrent word is eCurrent word is rCurrent word is fCurrent word is aCurrent word is cCurrent word is eCurrent word is fCurrent word is oCurrent word is rCurrent word is uCurrent word is sCurrent word is eCurrent word is rCurrent word is pCurrent word is rCurrent word is oCurrent word is gCurrent word is rCurrent word is aCurrent word is mCurrent word is sCurrent word is PCurrent word is oCurrent word is pCurrent word is uCurrent word is lCurrent word is aCurrent word is rCurrent word is dCurrent word is eCurrent word is sCurrent word is kCurrent word is tCurrent word is oCurrent word is pCurrent word is oCurrent word is pCurrent word is eCurrent word is rCurrent word is aCurrent word is tCurrent word is iCurrent word is nCurrent word is gCurrent word is sCurrent word is yCurrent word is sCurrent word is tCurrent word is eCurrent word is mCurrent word is sCurrent word is iCurrent word is nCurrent word is cCurrent word is lCurrent word is uCurrent word is dCurrent word is eCurrent word is WCurrent word is iCurrent word is nCurrent word is dCurrent word is oCurrent word is wCurrent word is sCurrent word is mCurrent word is aCurrent word is cCurrent word is OCurrent word is SCurrent word is LCurrent word is iCurrent word is nCurrent word is uCurrent word is x
- n�8�� is the longest word
- it is 1 characters long!student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- Current word is AnCurrent word is AoperatingCurrent word is AsystemCurrent word is AisCurrent word is AaCurrent word is AlayerCurrent word is AofCurrent word is AsophisticatedCurrent word is AsoftwareCurrent word is AthatCurrent word is AmanagesCurrent word is AhardwareCurrent word is AresourcesCurrent word is AandCurrent word is AprovidesCurrent word is AaCurrent word is AcommonCurrent word is AinterfaceCurrent word is AforCurrent word is AuserCurrent word is AprogramsCurrent word is APopularCurrent word is AdesktopCurrent word is AoperatingCurrent word is AsystemsCurrent word is AincludeCurrent word is AWindowsCurrent word is AmacOS
- Asophisticated is the longest word
- it is 14 characters long!student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- AnAoperatingAsystemAisAaAlayerAofAsophisticatedAsoftwareAthatAmanagesAhardwareAresourcesAandAprovidesAaAcommonAinterfaceAforAuserAprogramsAPopularAdesktopAoperatingAsystemsAincludeAWindowsAmacOS
- Asophisticated is the longest word
- it is 14 characters long!student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- AnoperatingsystemisalayerofsophisticatedsoftwarethatmanageshardwareresourcesandprovidesacommoninterfaceforuserprogramsPopulardesktopoperatingsystemsincludeWindowsmacOS
- sophisticated is the longest word
- it is 13 characters long!student@student64:~/cnlabs/workshop02$ make task5
- gcc task5.c -o task5 -std=c99 -Wall
- student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
- sophisticated is the longest word!
- it is 13 characters long!
- student@student64:~/cnlabs/workshop02$
- ## task5.c CODE ##
- #include <stdio.h>
- #include <unistd.h>
- #include <ctype.h>
- #include <string.h>
- static const int max_word_len = 50;
- void copy(char src[], char dst[], int count){
- for (int i = 0; i < count; i++){
- dst[i] = src[i];
- if (src[i] == '\0'){
- break;
- }
- }
- }
- int main(int argc, const char *argv[])
- {
- char c = getchar();
- int i = 0;
- char currentWord[max_word_len];
- char longestWord[max_word_len];
- int longestWordSize = 0;
- while (c != EOF && i < max_word_len-1) {
- if (c != '\n'){
- currentWord[i] = c;
- currentWord[i+1] = '\0';
- i += 1;
- }else{
- if (strlen(currentWord) > longestWordSize){
- longestWordSize = strlen(currentWord);
- copy (currentWord, longestWord, strlen(currentWord));
- }
- //printf("%s", currentWord);
- i = 0;
- }
- c = getchar();
- }
- printf("\n%s is the longest word!", longestWord);
- printf("\nIt is %d characters long!\n", longestWordSize);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement