I am having trouble getting this to work. What I want to do is take user input example 1 2 3 and then multiple each character by 2 so output would be 2 4 6. Eventually I will take a long string of numbers and multiply every other character in the string by 2 leaving the rest untouched.
The problem I a having now is that I think it is multiplying the ASCII value by 2 not the actual integer by 2. Below is the code I have so far I haven’t added any error checking to it yet to make sure the user inputs only numbers and not more than 16 etc. I am new to programming in C and am just doing this to learn.
#include <stdio.h>
int main(void){
char numbers[17];
int i;
printf("Please enter number\n");
scanf("%s", &numbers);
for(int i=0;i<strlen(numbers);i++){
printf("%c\n",numbers[i] * 2);
}
}
2 issues in your program
1)
2)
Here is a modfied program
Also, it’s better to avoid
scanf– http://c-faq.com/stdio/scanfprobs.html