user3326005
user3326005

Reputation: 1

Converting string of character values to decimal values in C without using printf

If a have a string of character values, lets say

char charstring[k] = "word";

How would I convert the values of that string into a new string of the same length that holds the decimal values of the character string? There is no need to print out the conversion, I merely need a new string with decimal values.

Upvotes: 0

Views: 107

Answers (2)

Heeryu
Heeryu

Reputation: 872

You already have:

#include <stdio.h>

int main(){
    char s[] = "word";
    char i;

    for(i=0; s[i]; i++){
       printf("%d or $%x\n", s[i], s[i]);
    }
}

Upvotes: 1

tabstop
tabstop

Reputation: 1761

If you have

char charstring[] = "word";

then the string of the same length that holds the decimal values of the character string is charstring. (Every character is stored internally as a number already.)

Upvotes: 1

Related Questions