fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. #define LINE_LENGTH 42
  5.  
  6. char* find_seperator(char line[]) {
  7. for (int i = 0; i < LINE_LENGTH; i++) {
  8. if (line[i] == ' ') {
  9. return &line[i];
  10. }
  11. }
  12. }
  13.  
  14. void encode_mask(char line[LINE_LENGTH], char *mask) {
  15. for (int i = 0; line[i] != '\0'; i++) {
  16. if (*mask++ == '1') {
  17. line[i] = toupper(line[i]);
  18. }
  19. }
  20. }
  21.  
  22. int main(int argc, char *args[]) {
  23. if (argc < 2) {
  24. fprintf(stderr, "File path not provided. Exiting...\n");
  25. return 1;
  26. }
  27.  
  28. if (argc > 2) {
  29. puts("Excessive arguments, only the first will be considered.");
  30. }
  31.  
  32. FILE *file = fopen(args[1], "r");
  33. if (file == NULL) {
  34. perror("Error");
  35. return 1;
  36. }
  37.  
  38. char line[LINE_LENGTH];
  39. while (fgets(line, LINE_LENGTH, file)) {
  40. char *mask = find_seperator(line);
  41. *mask++ = '\0';
  42. encode_mask(line, mask);
  43. puts(line);
  44. }
  45.  
  46. fclose(file);
  47. }
Runtime error #stdin #stdout #stderr 0s 2156KB
stdin
hello 11001
world 10000
cba 111
stdout
Standard output is empty
stderr
File path not provided. Exiting...