0

I need to make this work on Dev C++ and Visual Studio, but the string in function returns correctly only in GCC. I really don't know where is the error.

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <locale.h>


char* get_valid_string(char *string) {

  bool valid = false;
  char name[80];

  while (valid != true) {

      printf(" %s", string);
      fgets(name, sizeof(name), stdin);
      printf(" %s", name);

      char *valid_string = name;
      return valid_string;

   }

}

int main() {

  setlocale(LC_ALL, "Portuguese");

  char *title;
  char *string = "Title: ";
  title = get_valid_string(string);
  printf("%s", title);

system("PAUSE");

}
Pavindu
  • 2,684
  • 6
  • 44
  • 77
Forsaiken
  • 324
  • 3
  • 12

0 Answers0