6 Revīzijas a1a8c7d08a ... bb98a3f1dc

Autors SHA1 Ziņojums Datums
  muhammed bb98a3f1dc Merge branch 'muhammed' into notabug 1 gadu atpakaļ
  muhammed 57fc17960f Avoid using strlen in the inner loAvoid using strlen in the inner loop: The strlen function is called inside the loop, which can be slow for large strings. 1 gadu atpakaļ
  muhammed f1c3a8b6e9 fix '-f' bug 1 gadu atpakaļ
  muhammed ff070ac1bd remove '-f' bug 1 gadu atpakaļ
  muhammed 7cb8be0e7a fix '-f' in the middle 1 gadu atpakaļ
  muhammed d22ad64d41 add tcc to cc variable 1 gadu atpakaļ
3 mainītis faili ar 6 papildinājumiem un 3 dzēšanām
  1. 1 1
      Makefile
  2. BIN
      upper
  3. 5 2
      upper.c

+ 1 - 1
Makefile

@@ -1,4 +1,4 @@
-CC=cc
+CC=tcc
 
 upper: upper.c Makefile
 	$(CC) upper.c -o upper

BIN
upper


+ 5 - 2
upper.c

@@ -4,7 +4,7 @@
 #include <ctype.h>
 
 int w_count = 1;
-int f_check;
+int f_check, str_len, j;
 
 /* help message */
 void print_help()
@@ -34,8 +34,11 @@ int main(int argc, char *argv[])
 		/* if '-f' in middle exit with help message */
 		if(w_count != 1 && !strcmp(argv[w_count], "-f"))
 			print_help();
+
+		/* length of word */
+		str_len = strlen(argv[w_count]);
 		/*print characters for each word */
-		for (int j = 0; j < strlen(argv[w_count]); j += 1) {
+		for (j = 0; j < str_len; j += 1) {
 			/* 
 			 * if '-f' option is enable 
 			 * then print uppercase first character only (arg[i][0])