How to make a string "transformed into a number"

1

I have an exercise to make the user type a word and it is transformed by their corresponding numbers from the ASCII table.

EXAMPLE : sara would print 115 97 114 97

this is the code:

NOTE: I put a fixed value in the vector just for testing. The result of this is causing two problems:

  • At the time of rendering values, the first value (type prints ara and not sara )

  • And also prints odd numbers like -14

    {
      int i;
      char texto[15] ;
    
      printf("digite uma palavra");
      gets(texto);
      fflush(stdin);
      scanf ("%c",texto);
    
      for (i=0; i<15; i++)
      {
        printf("Valor do elemento %d da string = %d\n",i, texto[i]);
      }
    
      getch();
    }
    
asked by anonymous 28.11.2018 / 15:34

1 answer

0

Hi, trying to solve your problem I will list some functions of string conversion that may be useful but remember to include the library: strings.h

double atof (const char * string) Converts a string to a real value.

int atoi (const char * string) Converts a string to an integer value.

int atol (const char * string) Converts a string to a long integer value.

sprintf (char * string, const * char format, double number) Converts a number to string.

    
30.11.2018 / 01:06