FILE* f;  /// pointer to a File structure
  char cuv[100];
  int i;
  f = fopen("exmp.txt", "a+");  /// open the file and add the registry. the end
  puts("enter words to add to file");
  for (i = 1; i <= 3; i++) {
    gets(cuv);  /// enters the character string
    fprintf(f, "% s", cuv);
  }  /// write
  puts("File contents:");
  rewind(f);               /// goes to the beginning of the file
  fscanf(f, "% s", &cuv);  /// read
  puts(cuv);               /// displaying the string on the screen by adding \ n
  getch();
  fclose(f);
}  /// close the file
I have this program that adds words to the end of the file which works fine but i want it to swap the letter a with the letter b and vice versa
I found a piece of code that does what i want but i cant seem to get it working. If i change something it just breaks the code
for (int a = 0; a < strlen(cuv); a++){
  if (cuv[a] == 'a'){
    cuv[a] = m;
  } else if(cuv[a] == 'b'){
    cuv[a] = c;
  }
}
Is there a simpler way to just swap 2 characters?
 
    