Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.17 KB | None | 0 0
  1. ## Checkpoint 6 Terminal Code ##
  2.  
  3. student@student64:~$ ls
  4. cnlabs Documents Music Public Videos
  5. Desktop Downloads Pictures Templates
  6. student@student64:~$ cd ~/cnlabs/workshop02
  7. student@student64:~/cnlabs/workshop02$ make task1
  8. cc task1.c -o task1
  9. student@student64:~/cnlabs/workshop02$ ./task1
  10. Please enter some input: reee
  11. Your input was: reee
  12. student@student64:~/cnlabs/workshop02$ ./task1 <OperatingSystem.txt
  13. 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:
  14. - Windows
  15. - macOS
  16. - Linux
  17. student@student64:~/cnlabs/workshop02$ make task1
  18. cc task1.c -o task1
  19. student@student64:~/cnlabs/workshop02$ ./task1 <OperatingSystem.txt
  20. 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:
  21. - Windows
  22. - macOS
  23. - Linux
  24. student@student64:~/cnlabs/workshop02$
  25.  
  26. ## Checkpoint 6 task1.c code ##
  27. #include <stdio.h>
  28.  
  29. int main() {
  30. int nextChar;
  31. nextChar = getchar();
  32.  
  33. while (nextChar != EOF){
  34. putchar(nextChar);
  35. nextChar = getchar();
  36. }
  37.  
  38. return 0;
  39. }
  40.  
  41. ## Checkpoint 7 Terminal window ## NOTE: This was a messy one, sorry for the length of things.
  42. student@student64:~/cnlabs/workshop02$ make task2
  43. gcc task2.c -o task2 -std=c99 -Wall
  44. task2.c: In function ‘main’:
  45. task2.c:11:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  46. usleep(2);
  47. ^~~~~~
  48. student@student64:~/cnlabs/workshop02$ ./task2 this is a test
  49. student@student64:~/cnlabs/workshop02$ make task2
  50. gcc task2.c -o task2 -std=c99 -Wall
  51. task2.c: In function ‘main’:
  52. task2.c:10:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  53. usleep(2);
  54. ^~~~~~
  55. student@student64:~/cnlabs/workshop02$ make task2
  56. gcc task2.c -o task2 -std=c99 -Wall
  57. task2.c: In function ‘main’:
  58. task2.c:10:7: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
  59. nanosleep(2);
  60. ^~~~~~~~~
  61. student@student64:~/cnlabs/workshop02$ make task2
  62. gcc task2.c -o task2 -std=c99 -Wall
  63. task2.c: In function ‘main’:
  64. task2.c:12:7: warning: implicit declaration of function ‘uleep’ [-Wimplicit-function-declaration]
  65. uleep(useconds_t 2);
  66. ^~~~~
  67. task2.c:12:13: error: ‘useconds_t’ undeclared (first use in this function)
  68. uleep(useconds_t 2);
  69. ^~~~~~~~~~
  70. task2.c:12:13: note: each undeclared identifier is reported only once for each function it appears in
  71. task2.c:12:24: error: expected ‘)’ before numeric constant
  72. uleep(useconds_t 2);
  73. ^
  74. makefile:4: recipe for target 'task2' failed
  75. make: *** [task2] Error 1
  76. student@student64:~/cnlabs/workshop02$ make task2
  77. gcc task2.c -o task2 -std=c99 -Wall
  78. task2.c: In function ‘main’:
  79. task2.c:12:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  80. usleep(2);
  81. ^~~~~~
  82. student@student64:~/cnlabs/workshop02$ make task2
  83. gcc task2.c -o task2 -std=c99 -Wall
  84. task2.c: In function ‘main’:
  85. task2.c:13:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  86. usleep(2);
  87. ^~~~~~
  88. student@student64:~/cnlabs/workshop02$ ./task2 testing
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. student@student64:~/cnlabs/workshop02$ ./task2 hello hello
  104. student@student64:~/cnlabs/workshop02$ make task2
  105. gcc task2.c -o task2 -std=c99 -Wall
  106. task2.c: In function ‘main’:
  107. task2.c:14:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  108. usleep(usecs);
  109. ^~~~~~
  110. student@student64:~/cnlabs/workshop02$ ./task2 hello hello
  111. student@student64:~/cnlabs/workshop02$ make task2
  112. gcc task2.c -o task2 -std=c99 -Wall
  113. task2.c: In function ‘main’:
  114. task2.c:6:15: warning: unused variable ‘usecs’ [-Wunused-variable]
  115. unsigned int usecs = 2;
  116. ^~~~~
  117. student@student64:~/cnlabs/workshop02$ ./task2 hello hello
  118. student@student64:~/cnlabs/workshop02$ make task2
  119. gcc task2.c -o task2 -std=c99 -Wall
  120. task2.c: In function ‘main’:
  121. task2.c:6:15: warning: unused variable ‘usecs’ [-Wunused-variable]
  122. unsigned int usecs = 2;
  123. ^~~~~
  124. student@student64:~/cnlabs/workshop02$ ./task2 hello hello
  125. student@student64:~/cnlabs/workshop02$ make task2
  126. gcc task2.c -o task2 -std=c99 -Wall
  127. student@student64:~/cnlabs/workshop02$ ./task2 hello hello
  128. student@student64:~/cnlabs/workshop02$ ./task1 hello hello
  129. student@student64:~/cnlabs/workshop02$ ./task1 hello hello
  130. hello
  131. hello
  132. student@student64:~/cnlabs/workshop02$ make task2
  133. makefile:4: warning: overriding recipe for target 'hello'
  134. makefile:2: warning: ignoring old recipe for target 'hello'
  135. cc task2.c -o task2
  136. student@student64:~/cnlabs/workshop02$ make task2
  137. make: 'task2' is up to date.
  138. student@student64:~/cnlabs/workshop02$ ./task2
  139. hello hello how are you
  140. hello hello how are you
  141. student@student64:~/cnlabs/workshop02$ make task2
  142. gcc task2.c -o task2 -std=c99 -Wall
  143. task2.c: In function ‘main’:
  144. task2.c:12:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  145. usleep(2000);
  146. ^~~~~~
  147. student@student64:~/cnlabs/workshop02$ ./task2 <OperatingSystem.txt
  148. 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:
  149. - Windows
  150. - macOS
  151. - Linux
  152. student@student64:~/cnlabs/workshop02$ make task2
  153. gcc task2.c -o task2 -std=c99 -Wall
  154. task2.c: In function ‘main’:
  155. task2.c:13:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  156. usleep(usecs);
  157. ^~~~~~
  158. student@student64:~/cnlabs/workshop02$ ./task2 <OperatingSystem.txt
  159. 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:
  160. - Windows
  161. - macOS
  162. - Linux
  163. student@student64:~/cnlabs/workshop02$ make task2
  164. gcc task2.c -o task2 -std=c99 -Wall
  165. task2.c: In function ‘main’:
  166. task2.c:13:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  167. usleep(usecs);
  168. ^~~~~~
  169. student@student64:~/cnlabs/workshop02$ ./task2 <OperatingSystem.txt
  170. 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:
  171. - Windows
  172. - macOS
  173. - Linux
  174. student@student64:~/cnlabs/workshop02$ ^C
  175. student@student64:~/cnlabs/workshop02$
  176.  
  177. ## Checkpoint 7 task2.c ##
  178. #include <stdio.h>
  179. #include <unistd.h>
  180.  
  181. int main() {
  182. int nextChar;
  183. unsigned int usecs = 20000;
  184.  
  185. nextChar = getchar();
  186.  
  187. while (nextChar != EOF){
  188. if (nextChar == ' '){
  189. fflush (stdout);
  190. usleep(usecs);
  191. }
  192. putchar(nextChar);
  193. nextChar = getchar();
  194. }
  195. return 0;
  196. }
  197.  
  198. ## Checkpoint 8 task3.c ##
  199. student@student64:~/cnlabs/workshop02$ make task3
  200. gcc task3.c -o task3 -std=c99 -Wall
  201. task3.c: In function ‘main’:
  202. task3.c:14:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  203. usleep(usecs);
  204. ^~~~~~
  205. task3.c:15:17: warning: missing terminating ' character
  206. putchar('\n')'
  207. ^
  208. task3.c:15:17: error: missing terminating ' character
  209. task3.c:16:3: error: expected ‘;’ before ‘}’ token
  210. }
  211. ^
  212. makefile:6: recipe for target 'task3' failed
  213. make: *** [task3] Error 1
  214. student@student64:~/cnlabs/workshop02$ make task3
  215. gcc task3.c -o task3 -std=c99 -Wall
  216. task3.c: In function ‘main’:
  217. task3.c:14:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  218. usleep(usecs);
  219. ^~~~~~
  220. student@student64:~/cnlabs/workshop02$ ./task3 <OperatingSystem.txt
  221. An
  222. operating
  223. system
  224. is
  225. a
  226. layer
  227. of
  228. sophisticated
  229. software
  230. that
  231. manages
  232. hardware
  233. resources
  234. and
  235. provides
  236. a
  237. common
  238. interface
  239. for
  240. user
  241. programs
  242. Popular
  243. desktop
  244. operating
  245. systems
  246. include
  247. Windows
  248. macOS
  249. Linuxstudent@student64:~/cnlabs/workshop02$ ./task3 <OperatingSystem.txt >Words.txt
  250. student@student64:~/cnlabs/workshop02$ cat Words.txt
  251. An
  252. operating
  253. system
  254. is
  255. a
  256. layer
  257. of
  258. sophisticated
  259. software
  260. that
  261. manages
  262. hardware
  263. resources
  264. and
  265. provides
  266. a
  267. common
  268. interface
  269. for
  270. user
  271. programs
  272. Popular
  273. desktop
  274. operating
  275. systems
  276. include
  277. Windows
  278. macOS
  279. student@student64:~/cnlabs/workshop02$
  280.  
  281. ## CHECKPOINT 8 task3.c ##
  282. #include <stdio.h>
  283. #include <unistd.h>
  284. #include <ctype.h>
  285.  
  286. int main() {
  287. int nextChar;
  288. unsigned int usecs = 20000;
  289.  
  290. nextChar = getchar();
  291.  
  292. while (nextChar != EOF){
  293. if (nextChar == ' '){
  294. fflush (stdout);
  295. usleep(usecs);
  296. putchar('\n');
  297. }
  298.  
  299. if (isalpha(nextChar)){
  300. putchar(nextChar);
  301. }
  302.  
  303. nextChar = getchar();
  304. }
  305. return 0;
  306. }
  307.  
  308. ## checkpoint 9 terminal code (note: this is another messy one sorry) ##
  309. student@student64:~/cnlabs/workshop02$ make task4
  310. gcc task4.c -o task4 -std=c99 -Wall
  311. task4.c: In function ‘charCheck’:
  312. task4.c:38:2: warning: no return statement in function returning non-void [-Wreturn-type]
  313. }
  314. ^
  315. task4.c: In function ‘main’:
  316. task4.c:43:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  317. usleep(usecs);
  318. ^~~~~~
  319. task4.c:55:9: error: ‘wordCount’ undeclared (first use in this function)
  320. printf(wordCount + "words");
  321. ^~~~~~~~~
  322. task4.c:55:9: note: each undeclared identifier is reported only once for each function it appears in
  323. task4.c:56:9: error: ‘characterCount’ undeclared (first use in this function)
  324. printf(characterCount + "characters");
  325. ^~~~~~~~~~~~~~
  326. At top level:
  327. task4.c:17:6: warning: ‘charCheck’ defined but not used [-Wunused-function]
  328. int charCheck(int c){
  329. ^~~~~~~~~
  330. makefile:8: recipe for target 'task4' failed
  331. make: *** [task4] Error 1
  332. student@student64:~/cnlabs/workshop02$ make task4
  333. gcc task4.c -o task4 -std=c99 -Wall
  334. task4.c: In function ‘charCheck’:
  335. task4.c:48:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
  336. usleep(usecs);
  337. ^~~~~~
  338. task4.c:61:9: error: ‘characterCount’ undeclared (first use in this function)
  339. printf(characterCount + "characters");
  340. ^~~~~~~~~~~~~~
  341. task4.c:61:9: note: each undeclared identifier is reported only once for each function it appears in
  342. task4.c: In function ‘main’:
  343. task4.c:67:1: error: expected declaration or statement at end of input
  344. }
  345. ^
  346. At top level:
  347. task4.c:18:6: warning: ‘charCheck’ defined but not used [-Wunused-function]
  348. int charCheck(int c){
  349. ^~~~~~~~~
  350. makefile:8: recipe for target 'task4' failed
  351. make: *** [task4] Error 1
  352. student@student64:~/cnlabs/workshop02$ make task4
  353. gcc task4.c -o task4 -std=c99 -Wall
  354. task4.c: In function ‘main’:
  355. task4.c:68:1: error: expected declaration or statement at end of input
  356. }
  357. ^
  358. At top level:
  359. task4.c:18:6: warning: ‘charCheck’ defined but not used [-Wunused-function]
  360. int charCheck(int c){
  361. ^~~~~~~~~
  362. makefile:8: recipe for target 'task4' failed
  363. make: *** [task4] Error 1
  364. student@student64:~/cnlabs/workshop02$ make task4
  365. gcc task4.c -o task4 -std=c99 -Wall
  366. task4.c: In function ‘charCheck’:
  367. task4.c:43:2: warning: no return statement in function returning non-void [-Wreturn-type]
  368. }
  369. ^
  370. student@student64:~/cnlabs/workshop02$ make task4
  371. gcc task4.c -o task4 -std=c99 -Wall
  372. student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
  373. An
  374. operating
  375. system
  376. is
  377. a
  378. layer
  379. of
  380. sophisticated
  381. software
  382. that
  383. manages
  384. hardware
  385. resources
  386. and
  387. provides
  388. a
  389. common
  390. interface
  391. for
  392. user
  393. programs
  394. Popular
  395. desktop
  396. operating
  397. systems
  398. include
  399. Windows
  400. macOS
  401. LinuxsFJ
  402. �x
  403. �$asestudent@student64:~/cnlabs/workshop02$ ./task4 <Operatingmake task4
  404. gcc task4.c -o task4 -std=c99 -Wall
  405. task4.c: In function ‘main’:
  406. task4.c:60:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  407. printf(lineCount, " lines");
  408. ^~~~~~~~~
  409. In file included from task4.c:1:0:
  410. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  411. extern int printf (const char *__restrict __format, ...);
  412. ^~~~~~
  413. task4.c:61:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  414. printf(wordCount, " words");
  415. ^~~~~~~~~
  416. In file included from task4.c:1:0:
  417. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  418. extern int printf (const char *__restrict __format, ...);
  419. ^~~~~~
  420. task4.c:62:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  421. printf(charCount, " characters");
  422. ^~~~~~~~~
  423. In file included from task4.c:1:0:
  424. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  425. extern int printf (const char *__restrict __format, ...);
  426. ^~~~~~
  427. task4.c:63:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  428. printf(vowelCount, " vowels");
  429. ^~~~~~~~~~
  430. In file included from task4.c:1:0:
  431. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  432. extern int printf (const char *__restrict __format, ...);
  433. ^~~~~~
  434. task4.c:64:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  435. printf(lowerCount, " lowercase");
  436. ^~~~~~~~~~
  437. In file included from task4.c:1:0:
  438. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  439. extern int printf (const char *__restrict __format, ...);
  440. ^~~~~~
  441. task4.c:65:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  442. printf(upperCount, " uppercase");
  443. ^~~~~~~~~~
  444. In file included from task4.c:1:0:
  445. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  446. extern int printf (const char *__restrict __format, ...);
  447. ^~~~~~
  448. student@student64:~/cnlabs/workshop02$ make task4
  449. gcc task4.c -o task4 -std=c99 -Wall
  450. task4.c: In function ‘main’:
  451. task4.c:60:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  452. printf(lineCount);
  453. ^~~~~~~~~
  454. In file included from task4.c:1:0:
  455. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  456. extern int printf (const char *__restrict __format, ...);
  457. ^~~~~~
  458. task4.c:61:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  459. printf(wordCount);
  460. ^~~~~~~~~
  461. In file included from task4.c:1:0:
  462. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  463. extern int printf (const char *__restrict __format, ...);
  464. ^~~~~~
  465. task4.c:62:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  466. printf(charCount);
  467. ^~~~~~~~~
  468. In file included from task4.c:1:0:
  469. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  470. extern int printf (const char *__restrict __format, ...);
  471. ^~~~~~
  472. task4.c:63:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  473. printf(vowelCount);
  474. ^~~~~~~~~~
  475. In file included from task4.c:1:0:
  476. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  477. extern int printf (const char *__restrict __format, ...);
  478. ^~~~~~
  479. task4.c:64:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  480. printf(lowerCount);
  481. ^~~~~~~~~~
  482. In file included from task4.c:1:0:
  483. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  484. extern int printf (const char *__restrict __format, ...);
  485. ^~~~~~
  486. task4.c:65:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  487. printf(upperCount);
  488. ^~~~~~~~~~
  489. In file included from task4.c:1:0:
  490. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  491. extern int printf (const char *__restrict __format, ...);
  492. ^~~~~~
  493. student@student64:~/cnlabs/workshop02$ make task4
  494. gcc task4.c -o task4 -std=c99 -Wall
  495. task4.c: In function ‘main’:
  496. task4.c:60:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  497. printf((char)lineCount);
  498. ^
  499. In file included from task4.c:1:0:
  500. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  501. extern int printf (const char *__restrict __format, ...);
  502. ^~~~~~
  503. task4.c:61:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  504. printf((char)wordCount);
  505. ^
  506. In file included from task4.c:1:0:
  507. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  508. extern int printf (const char *__restrict __format, ...);
  509. ^~~~~~
  510. task4.c:62:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  511. printf((char)charCount);
  512. ^
  513. In file included from task4.c:1:0:
  514. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  515. extern int printf (const char *__restrict __format, ...);
  516. ^~~~~~
  517. task4.c:63:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  518. printf((char)vowelCount);
  519. ^
  520. In file included from task4.c:1:0:
  521. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  522. extern int printf (const char *__restrict __format, ...);
  523. ^~~~~~
  524. task4.c:64:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  525. printf((char)lowerCount);
  526. ^
  527. In file included from task4.c:1:0:
  528. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  529. extern int printf (const char *__restrict __format, ...);
  530. ^~~~~~
  531. task4.c:65:9: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  532. printf((char)upperCount);
  533. ^
  534. In file included from task4.c:1:0:
  535. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  536. extern int printf (const char *__restrict __format, ...);
  537. ^~~~~~
  538. student@student64:~/cnlabs/workshop02$ make task4
  539. gcc task4.c -o task4 -std=c99 -Wall
  540. student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
  541. An
  542. operating
  543. system
  544. is
  545. a
  546. layer
  547. of
  548. sophisticated
  549. software
  550. that
  551. manages
  552. hardware
  553. resources
  554. and
  555. provides
  556. a
  557. common
  558. interface
  559. for
  560. user
  561. programs
  562. Popular
  563. desktop
  564. operating
  565. systems
  566. include
  567. Windows
  568. macOS
  569. Linux4 lines209 words172 characters209 vowels166 lowercase6 uppercasestudent@student64:~/cnlabs/workshop02$ make task4
  570. gcc task4.c -o task4 -std=c99 -Wall
  571. student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
  572. An
  573. operating
  574. system
  575. is
  576. a
  577. layer
  578. of
  579. sophisticated
  580. software
  581. that
  582. manages
  583. hardware
  584. resources
  585. and
  586. provides
  587. a
  588. common
  589. interface
  590. for
  591. user
  592. programs
  593. Popular
  594. desktop
  595. operating
  596. systems
  597. include
  598. Windows
  599. macOS
  600. Linux
  601. 4 lines
  602. 209 words
  603. 172 characters
  604. 209 vowels
  605. 166 lowercase
  606. 6 uppercasestudent@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txmake task4
  607. gcc task4.c -o task4 -std=c99 -Wall
  608. student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
  609. An
  610. operating
  611. system
  612. is
  613. a
  614. layer
  615. of
  616. sophisticated
  617. software
  618. that
  619. manages
  620. hardware
  621. resources
  622. and
  623. provides
  624. a
  625. common
  626. interface
  627. for
  628. user
  629. programs
  630. Popular
  631. desktop
  632. operating
  633. systems
  634. include
  635. Windows
  636. macOS
  637. Linux
  638. 4 lines
  639. 32 words
  640. 172 characters
  641. 209 vowels
  642. 166 lowercase
  643. 6 uppercasestudent@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txmake task4
  644. gcc task4.c -o task4 -std=c99 -Wall
  645. student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
  646. An
  647. operating
  648. system
  649. is
  650. a
  651. layer
  652. of
  653. sophisticated
  654. software
  655. that
  656. manages
  657. hardware
  658. resources
  659. and
  660. provides
  661. a
  662. common
  663. interface
  664. for
  665. user
  666. programs
  667. Popular
  668. desktop
  669. operating
  670. systems
  671. include
  672. Windows
  673. macOS
  674. Linux
  675. 4 lines
  676. 32 words
  677. 209 characters
  678. 209 vowels
  679. 166 lowercase
  680. 6 uppercasestudent@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txmake task4
  681. gcc task4.c -o task4 -std=c99 -Wall
  682. student@student64:~/cnlabs/workshop02$ ./task4 <OperatingSystem.txt
  683. An
  684. operating
  685. system
  686. is
  687. a
  688. layer
  689. of
  690. sophisticated
  691. software
  692. that
  693. manages
  694. hardware
  695. resources
  696. and
  697. provides
  698. a
  699. common
  700. interface
  701. for
  702. user
  703. programs
  704. Popular
  705. desktop
  706. operating
  707. systems
  708. include
  709. Windows
  710. macOS
  711. Linux
  712. 4 lines
  713. 32 words
  714. 209 characters
  715. 65 vowels
  716. 166 lowercase
  717. 6 uppercase
  718. student@student64:~/cnlabs/workshop02$
  719.  
  720. ## checkpoint 9 task4.c code ##
  721. #include <stdio.h>
  722. #include <unistd.h>
  723. #include <ctype.h>
  724.  
  725. int main() {
  726. int nextChar;
  727. int lineCount = 0;
  728. int wordCount = 0;
  729. int charCount = 0;
  730. int vowelCount = 0;
  731. int upperCount = 0;
  732. int lowerCount = 0;
  733.  
  734. //unsigned int usecs = 20000;
  735.  
  736. nextChar = getchar();
  737.  
  738. int charCheck(int c){
  739. if (c == '\n'){
  740. lineCount += 1;
  741. }
  742.  
  743. if (isspace(c)){
  744. wordCount += 1;
  745. }
  746.  
  747. if (isalpha(c)){
  748. //charCount += 1;
  749. }
  750.  
  751. if (tolower(c) == 'a' || tolower(c) == 'e' || tolower(c) == 'i' || tolower(c) == 'o' || tolower(c) == 'u'){
  752. vowelCount += 1;
  753. }
  754.  
  755. if (islower(c)){
  756. lowerCount += 1;
  757. }
  758.  
  759. if (isupper(c)){
  760. upperCount += 1;
  761. }
  762. return 0;
  763. }
  764.  
  765. while (nextChar != EOF){
  766. charCheck(nextChar);
  767. charCount += 1;
  768. if (nextChar == ' '){
  769. fflush (stdout);
  770. //usleep(usecs);
  771. putchar('\n');
  772. }
  773.  
  774. if (isalpha(nextChar)){
  775. putchar(nextChar);
  776. }
  777.  
  778. nextChar = getchar();
  779. }
  780.  
  781. printf("\n%d lines", lineCount);
  782. printf("\n%d words", wordCount);
  783. printf("\n%d characters", charCount);
  784. printf("\n%d vowels", vowelCount);
  785. printf("\n%d lowercase", lowerCount);
  786. printf("\n%d uppercase\n", upperCount);
  787.  
  788. return 0;
  789. }
  790.  
  791. ## Checkpoint 10 terminal code ##
  792. hardware
  793. resources
  794. and
  795. provides
  796. a
  797. common
  798. interface
  799. for
  800. user
  801. programs
  802. Popular
  803. desktop
  804. operating
  805. systems
  806. include
  807. Windows
  808. macOS
  809. Linux
  810. 4 lines
  811. 32 words
  812. 209 characters
  813. 65 vowels
  814. 166 lowercase
  815. 6 uppercase
  816. student@student64:~/cnlabs/workshop02$ make task5
  817. gcc task5.c -o task5 -std=c99 -Wall
  818. task5.c: In function ‘main’:
  819. task5.c:18:10: warning: implicit declaration of function ‘getChar’ [-Wimplicit-function-declaration]
  820. int c = getChar();
  821. ^~~~~~~
  822. task5.c:26:7: error: ‘nextChar’ undeclared (first use in this function)
  823. if (nextChar != '\n'){
  824. ^~~~~~~~
  825. task5.c:26:7: note: each undeclared identifier is reported only once for each function it appears in
  826. task5.c:29:8: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
  827. if (strlen(currentWord) > longestWordSize){
  828. ^~~~~~
  829. task5.c:29:8: warning: incompatible implicit declaration of built-in function ‘strlen’
  830. task5.c:29:8: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
  831. makefile:10: recipe for target 'task5' failed
  832. make: *** [task5] Error 1
  833. student@student64:~/cnlabs/workshop02$ make task5
  834. gcc task5.c -o task5 -std=c99 -Wall
  835. task5.c: In function ‘main’:
  836. task5.c:26:7: error: ‘nextChar’ undeclared (first use in this function)
  837. if (nextChar != '\n'){
  838. ^~~~~~~~
  839. task5.c:26:7: note: each undeclared identifier is reported only once for each function it appears in
  840. task5.c:29:8: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
  841. if (strlen(currentWord) > longestWordSize){
  842. ^~~~~~
  843. task5.c:29:8: warning: incompatible implicit declaration of built-in function ‘strlen’
  844. task5.c:29:8: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
  845. makefile:10: recipe for target 'task5' failed
  846. make: *** [task5] Error 1
  847. student@student64:~/cnlabs/workshop02$ make task5
  848. gcc task5.c -o task5 -std=c99 -Wall
  849. task5.c: In function ‘main’:
  850. task5.c:29:8: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
  851. if (strlen(currentWord) > longestWordSize){
  852. ^~~~~~
  853. task5.c:29:8: warning: incompatible implicit declaration of built-in function ‘strlen’
  854. task5.c:29:8: note: include ‘<string.h>’ or provide a declaration of ‘strlen’
  855. student@student64:~/cnlabs/workshop02$ make task5
  856. gcc task5.c -o task5 -std=c99 -Wall
  857. task5.c: In function ‘main’:
  858. task5.c:34:49: error: expected ‘;’ before ‘)’ token
  859. copy (currentWord, longestWord, arrayLength));
  860. ^
  861. task5.c:34:49: error: expected statement before ‘)’ token
  862. makefile:10: recipe for target 'task5' failed
  863. make: *** [task5] Error 1
  864. student@student64:~/cnlabs/workshop02$ make task5
  865. gcc task5.c -o task5 -std=c99 -Wall
  866. student@student64:~/cnlabs/workshop02$ ./task 5 <Words.txt
  867. bash: ./task: No such file or directory
  868. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  869. test
  870. what
  871. is
  872. going
  873. on
  874. I
  875. hate
  876. this
  877. I
  878. wish
  879. I
  880. didn't
  881. have
  882. to
  883. write
  884. this
  885. aaaaaaa
  886.  
  887. ^C
  888. student@student64:~/cnlabs/workshop02$ make task5
  889. gcc task5.c -o task5 -std=c99 -Wall
  890. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  891.  
  892. n is the longest word
  893. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  894. gcc task5.c -o task5 -std=c99 -Wall
  895. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  896. n
  897. n is the longest word
  898. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  899. gcc task5.c -o task5 -std=c99 -Wall
  900. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  901. AnnoperatingsystemisalayerofsophisticatedsoftwarethatmanageshardwareresourcesandprovidesacommoninterfaceforuserprogramsPopulardesktopoperatingsystemsincludeWindowsmacOSLinux
  902. n is the longest word
  903. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  904. gcc task5.c -o task5 -std=c99 -Wall
  905. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  906. 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!
  907. n is the longest word
  908. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  909. gcc task5.c -o task5 -std=c99 -Wall
  910. task5.c: In function ‘main’:
  911. task5.c:36:10: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  912. printf(arrayLength);
  913. ^~~~~~~~~~~
  914. In file included from task5.c:1:0:
  915. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘int’
  916. extern int printf (const char *__restrict __format, ...);
  917. ^~~~~~
  918. student@student64:~/cnlabs/workshop02$ make task5
  919. gcc task5.c -o task5 -std=c99 -Wall
  920. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  921. 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
  922. n is the longest word
  923. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  924. gcc task5.c -o task5 -std=c99 -Wall
  925. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  926. nngmsarfdetsesdsanerrsrpgsesS
  927. n is the longest word
  928. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  929. gcc task5.c -o task5 -std=c99 -Wall
  930. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  931. 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
  932. n is the longest word
  933. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  934. gcc task5.c -o task5 -std=c99 -Wall
  935. task5.c: In function ‘main’:
  936. task5.c:31:4: warning: implicit declaration of function ‘strncat’ [-Wimplicit-function-declaration]
  937. strncat(currentWord, &c, 1);
  938. ^~~~~~~
  939. task5.c:31:4: warning: incompatible implicit declaration of built-in function ‘strncat’
  940. task5.c:31:4: note: include ‘<string.h>’ or provide a declaration of ‘strncat’
  941. task5.c:31:25: warning: passing argument 2 of ‘strncat’ from incompatible pointer type [-Wincompatible-pointer-types]
  942. strncat(currentWord, &c, 1);
  943. ^
  944. task5.c:31:25: note: expected ‘const char *’ but argument is of type ‘int *’
  945. student@student64:~/cnlabs/workshop02$ make task5
  946. gcc task5.c -o task5 -std=c99 -Wall
  947. task5.c: In function ‘main’:
  948. task5.c:32:25: warning: passing argument 2 of ‘strncat’ from incompatible pointer type [-Wincompatible-pointer-types]
  949. strncat(currentWord, &c, 1);
  950. ^
  951. In file included from task5.c:4:0:
  952. /usr/include/string.h:136:14: note: expected ‘const char * restrict’ but argument is of type ‘int *’
  953. extern char *strncat (char *__restrict __dest, const char *__restrict __src,
  954. ^~~~~~~
  955. student@student64:~/cnlabs/workshop02$ make task5
  956. gcc task5.c -o task5 -std=c99 -Wall
  957. task5.c: In function ‘main’:
  958. task5.c:32:25: warning: passing argument 2 of ‘strncat’ makes pointer from integer without a cast [-Wint-conversion]
  959. strncat(currentWord, c, 1);
  960. ^
  961. In file included from task5.c:4:0:
  962. /usr/include/string.h:136:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
  963. extern char *strncat (char *__restrict __dest, const char *__restrict __src,
  964. ^~~~~~~
  965. student@student64:~/cnlabs/workshop02$ make task5
  966. gcc task5.c -o task5 -std=c99 -Wall
  967. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  968. 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
  969. n is the longest word
  970. it is 50 characters long!student@student64:~/cnlabs/workshop02$ ./task5 <Wordmake task5
  971. gcc task5.c -o task5 -std=c99 -Wall
  972. task5.c: In function ‘main’:
  973. task5.c:31:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  974. strcat(currentWord,c);
  975. ^
  976. In file included from task5.c:4:0:
  977. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
  978. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  979. ^~~~~~
  980. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  981. Segmentation fault
  982. student@student64:~/cnlabs/workshop02$ make task5
  983. gcc task5.c -o task5 -std=c99 -Wall
  984. task5.c: In function ‘main’:
  985. task5.c:31:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  986. strcat(currentWord,(char)c);
  987. ^
  988. In file included from task5.c:4:0:
  989. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
  990. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  991. ^~~~~~
  992. student@student64:~/cnlabs/workshop02$ make task5
  993. gcc task5.c -o task5 -std=c99 -Wall
  994. task5.c: In function ‘main’:
  995. task5.c:31:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  996. strcat(currentWord,c);
  997. ^
  998. In file included from task5.c:4:0:
  999. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
  1000. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  1001. ^~~~~~
  1002. student@student64:~/cnlabs/workshop02$ make task5
  1003. gcc task5.c -o task5 -std=c99 -Wall
  1004. task5.c: In function ‘main’:
  1005. task5.c:29:23: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
  1006. strcat(currentWord,itoa(c));
  1007. ^~~~
  1008. task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  1009. In file included from task5.c:4:0:
  1010. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
  1011. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  1012. ^~~~~~
  1013. task5.c:32:3: error: ‘arrayLength’ undeclared (first use in this function)
  1014. arrayLength = sizeof(currentWord) / sizeof(currentWord[0]);
  1015. ^~~~~~~~~~~
  1016. task5.c:32:3: note: each undeclared identifier is reported only once for each function it appears in
  1017. makefile:10: recipe for target 'task5' failed
  1018. make: *** [task5] Error 1
  1019. student@student64:~/cnlabs/workshop02$ make task5
  1020. gcc task5.c -o task5 -std=c99 -Wall
  1021. task5.c: In function ‘main’:
  1022. task5.c:29:23: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
  1023. strcat(currentWord,itoa(c));
  1024. ^~~~
  1025. task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  1026. In file included from task5.c:4:0:
  1027. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘int’
  1028. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  1029. ^~~~~~
  1030. /tmp/ccG5cNMy.o: In function `main':
  1031. task5.c:(.text+0x175): undefined reference to `itoa'
  1032. collect2: error: ld returned 1 exit status
  1033. makefile:10: recipe for target 'task5' failed
  1034. make: *** [task5] Error 1
  1035. student@student64:~/cnlabs/workshop02$ make task5
  1036. gcc task5.c -o task5 -std=c99 -Wall
  1037. task5.c: In function ‘main’:
  1038. task5.c:29:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  1039. strcat(currentWord,(char *)c);
  1040. ^
  1041. student@student64:~/cnlabs/workshop02$ make task5
  1042. gcc task5.c -o task5 -std=c99 -Wall
  1043. task5.c: In function ‘main’:
  1044. task5.c:29:4: error: too many arguments to function ‘strcat’
  1045. strcat(currentWord,&c,1);
  1046. ^~~~~~
  1047. In file included from task5.c:4:0:
  1048. /usr/include/string.h:133:14: note: declared here
  1049. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  1050. ^~~~~~
  1051. makefile:10: recipe for target 'task5' failed
  1052. make: *** [task5] Error 1
  1053. student@student64:~/cnlabs/workshop02$ make task5
  1054. gcc task5.c -o task5 -std=c99 -Wall
  1055. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1056. 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��
  1057. Segmentation fault
  1058. student@student64:~/cnlabs/workshop02$ make task5
  1059. gcc task5.c -o task5 -std=c99 -Wall
  1060. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1061. 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��
  1062. Segmentation fault
  1063. student@student64:~/cnlabs/workshop02$ make task5
  1064. gcc task5.c -o task5 -std=c99 -Wall
  1065. task5.c: In function ‘main’:
  1066. task5.c:19:14: error: invalid initializer
  1067. char c[2] = getchar();
  1068. ^~~~~~~
  1069. task5.c:27:11: warning: comparison between pointer and integer
  1070. while (c != EOF && i < max_word_len-1) {
  1071. ^~
  1072. task5.c:28:9: warning: comparison between pointer and integer
  1073. if (c != '\n'){
  1074. ^~
  1075. task5.c:40:5: error: assignment to expression with array type
  1076. c = getchar();
  1077. ^
  1078. makefile:10: recipe for target 'task5' failed
  1079. make: *** [task5] Error 1
  1080. student@student64:~/cnlabs/workshop02$ make task5
  1081. gcc task5.c -o task5 -std=c99 -Wall
  1082. task5.c: In function ‘main’:
  1083. task5.c:22:2: error: variable-sized object may not be initialized
  1084. char currentWord[max_word_len] = '\0';
  1085. ^~~~
  1086. task5.c:23:2: error: variable-sized object may not be initialized
  1087. char longestWord[max_word_len] = '\0';
  1088. ^~~~
  1089. task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  1090. strcat(currentWord,c);
  1091. ^
  1092. In file included from task5.c:4:0:
  1093. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
  1094. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  1095. ^~~~~~
  1096. makefile:10: recipe for target 'task5' failed
  1097. make: *** [task5] Error 1
  1098. student@student64:~/cnlabs/workshop02$ make task5
  1099. gcc task5.c -o task5 -std=c99 -Wall
  1100. task5.c: In function ‘main’:
  1101. task5.c:29:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  1102. strcat(currentWord,c);
  1103. ^
  1104. In file included from task5.c:4:0:
  1105. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
  1106. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  1107. ^~~~~~
  1108. student@student64:~/cnlabs/workshop02$ make task5
  1109. gcc task5.c -o task5 -std=c99 -Wall
  1110. task5.c: In function ‘main’:
  1111. task5.c:29:11: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  1112. printf(c);
  1113. ^
  1114. In file included from task5.c:1:0:
  1115. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  1116. extern int printf (const char *__restrict __format, ...);
  1117. ^~~~~~
  1118. task5.c:30:23: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [-Wint-conversion]
  1119. strcat(currentWord,c);
  1120. ^
  1121. In file included from task5.c:4:0:
  1122. /usr/include/string.h:133:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
  1123. extern char *strcat (char *__restrict __dest, const char *__restrict __src)
  1124. ^~~~~~
  1125. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1126. Segmentation fault
  1127. student@student64:~/cnlabs/workshop02$ make task5
  1128. gcc task5.c -o task5 -std=c99 -Wall
  1129. task5.c: In function ‘main’:
  1130. task5.c:29:11: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast [-Wint-conversion]
  1131. printf(c);
  1132. ^
  1133. In file included from task5.c:1:0:
  1134. /usr/include/stdio.h:364:12: note: expected ‘const char * restrict’ but argument is of type ‘char’
  1135. extern int printf (const char *__restrict __format, ...);
  1136. ^~~~~~
  1137. student@student64:~/cnlabs/workshop02$ make task5
  1138. gcc task5.c -o task5 -std=c99 -Wall
  1139. task5.c: In function ‘main’:
  1140. task5.c:29:13: error: expected expression before ‘)’ token
  1141. printf(c*);
  1142. ^
  1143. makefile:10: recipe for target 'task5' failed
  1144. make: *** [task5] Error 1
  1145. student@student64:~/cnlabs/workshop02$ make task5
  1146. gcc task5.c -o task5 -std=c99 -Wall
  1147. task5.c: In function ‘main’:
  1148. task5.c:29:13: error: expected expression before ‘)’ token
  1149. printf(c&);
  1150. ^
  1151. makefile:10: recipe for target 'task5' failed
  1152. make: *** [task5] Error 1
  1153. student@student64:~/cnlabs/workshop02$ make task5
  1154. gcc task5.c -o task5 -std=c99 -Wall
  1155. task5.c: In function ‘main’:
  1156. task5.c:29:16: error: expected expression before ‘)’ token
  1157. printf("",c&);
  1158. ^
  1159. makefile:10: recipe for target 'task5' failed
  1160. make: *** [task5] Error 1
  1161. student@student64:~/cnlabs/workshop02$ make task5
  1162. gcc task5.c -o task5 -std=c99 -Wall
  1163. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1164. 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
  1165. n�8�� is the longest word
  1166. it is 1 characters long!student@student64:~/cnlabs/workshop02$ make task5
  1167. gcc task5.c -o task5 -std=c99 -Wall
  1168. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1169. 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
  1170. Asophisticated is the longest word
  1171. it is 14 characters long!student@student64:~/cnlabs/workshop02$ make task5
  1172. gcc task5.c -o task5 -std=c99 -Wall
  1173. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1174. AnAoperatingAsystemAisAaAlayerAofAsophisticatedAsoftwareAthatAmanagesAhardwareAresourcesAandAprovidesAaAcommonAinterfaceAforAuserAprogramsAPopularAdesktopAoperatingAsystemsAincludeAWindowsAmacOS
  1175. Asophisticated is the longest word
  1176. it is 14 characters long!student@student64:~/cnlabs/workshop02$ make task5
  1177. gcc task5.c -o task5 -std=c99 -Wall
  1178. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1179. AnoperatingsystemisalayerofsophisticatedsoftwarethatmanageshardwareresourcesandprovidesacommoninterfaceforuserprogramsPopulardesktopoperatingsystemsincludeWindowsmacOS
  1180. sophisticated is the longest word
  1181. it is 13 characters long!student@student64:~/cnlabs/workshop02$ make task5
  1182. gcc task5.c -o task5 -std=c99 -Wall
  1183. student@student64:~/cnlabs/workshop02$ ./task5 <Words.txt
  1184.  
  1185. sophisticated is the longest word!
  1186. it is 13 characters long!
  1187. student@student64:~/cnlabs/workshop02$
  1188.  
  1189. ## task5.c CODE ##
  1190. #include <stdio.h>
  1191. #include <unistd.h>
  1192. #include <ctype.h>
  1193. #include <string.h>
  1194.  
  1195. static const int max_word_len = 50;
  1196.  
  1197. void copy(char src[], char dst[], int count){
  1198. for (int i = 0; i < count; i++){
  1199. dst[i] = src[i];
  1200. if (src[i] == '\0'){
  1201. break;
  1202. }
  1203. }
  1204. }
  1205.  
  1206. int main(int argc, const char *argv[])
  1207. {
  1208. char c = getchar();
  1209. int i = 0;
  1210.  
  1211. char currentWord[max_word_len];
  1212. char longestWord[max_word_len];
  1213.  
  1214. int longestWordSize = 0;
  1215.  
  1216. while (c != EOF && i < max_word_len-1) {
  1217. if (c != '\n'){
  1218. currentWord[i] = c;
  1219. currentWord[i+1] = '\0';
  1220. i += 1;
  1221. }else{
  1222. if (strlen(currentWord) > longestWordSize){
  1223. longestWordSize = strlen(currentWord);
  1224. copy (currentWord, longestWord, strlen(currentWord));
  1225. }
  1226. //printf("%s", currentWord);
  1227. i = 0;
  1228. }
  1229. c = getchar();
  1230. }
  1231. printf("\n%s is the longest word!", longestWord);
  1232. printf("\nIt is %d characters long!\n", longestWordSize);
  1233.  
  1234. return 0;
  1235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement