6 Commits a1a8c7d08a ... bb98a3f1dc

Autor SHA1 Nachricht Datum
  muhammed bb98a3f1dc Merge branch 'muhammed' into notabug vor 1 Jahr
  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. vor 1 Jahr
  muhammed f1c3a8b6e9 fix '-f' bug vor 1 Jahr
  muhammed ff070ac1bd remove '-f' bug vor 1 Jahr
  muhammed 7cb8be0e7a fix '-f' in the middle vor 1 Jahr
  muhammed d22ad64d41 add tcc to cc variable vor 1 Jahr
3 geänderte Dateien mit 6 neuen und 3 gelöschten Zeilen
  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])