Answer the question
In order to leave comments, you need to log in
How to remove encoding from C++ program?
I want to copy certain elements from one array to another, but there was a problem: ASCII encoding appeared instead of the expected values.
Here is the screenshot:
Here is the code:
#include "stdafx.h"
#include <iostream>
#define MAX 50
using namespace std;
int main()
{
char str[50] = "12345678901";
int i,l;
double s1[MAX];
i = 0;
while(str[i] != '\0')
{
i++;
}
l = i / 2;
for(i = 0; i < l; i++)
{
s1[i] = str[i];
cout << s1[i] << endl;
}
system("pause");
return 0;
}
Answer the question
In order to leave comments, you need to log in
Well, everything is correct. You have three options:
1) Declaring the s1 array as a char array (or removing it altogether)
2) When copying from str to s1, convert it to a number (atof and others) (if you really need the s1 array)
3) When outputting to the console from s1 lead to char (the worst option)
It's hard to say exactly, because the purpose of the array s1, for example, is generally unclear - it can be thrown out altogether.
This is where
the implicit conversion char -> int -> double takes place. And with char -> int, of course, you get the same ascii character codes.
Perhaps you meant something like thiss1[i] = str[i] - '0';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question