Problem text :
Load a string ,which certainly can't be longer than 30 characters . If the loaded series
contains some characters other than uppercase and lowercase letters of the English alphabet and digits 0-9 , print
Message : loaded string not properly entered.
If an array is properly entered, it is necessary to amend a series so that the lowercase a, e , and substitute with
numbers 9,8,7 in the order given .
Print original , and the resulting string .
For example , the input string UlazniNizOd20Znakova prints:
UlazniNizOd20Znakova Ul9zn7NIZOd20Zn9kov9
Code:
#include <stdio.h>
#include <conio.h>
int main(){
char string[30+1];
int i;
scanf("%s", &string);
for( i = 0; string[i] != '\0'; i++){
if( !(string[i] >= '0' && string[i] <= '9' || string[i] >= 'a' && string[i] <= 'z' || string[i] >= 'A' && string[i] <= 'Z') ){
printf("Loaded string is not properly entered.");
}
}
char changedString[30+1] = string;
for( i = 0; i < 31; i++){
if(string[i] == 'a'){
string[i] = '9';
}else if(string[i] == 'b'){
string[i] = '8';
}else if( string[i] == 'c'){
string[i] = '7';
}
}
printf("Unchanged string: %s\n", string);
printf("Changed string: %s", changedString);
}
How to assign array to an array variable,
and why my approach won't work ( guess it has to do something with adresses of the variables)
I assume that in this kind of problems we use pointers but I just started learning about the pointers so I am not so practical with using them yet.