C
Carramba
hi!
I have strange (well to my enyway) problem the code below works like a
sweiz clock if it used for integers, but if I try to put char in it by
interacting with user, for loop ll doubble jump and insern char in
everyother place in vector. I'am guessing it some kind of problem becouse
when asking after char and press Enter I get 8 bits char en enter, is this
the issue? how to comme arround it?
I have tryed to use getchar() but it behavs in the sameway as scanf(),
Element 0 a
Element 1
Element 2 b
Element 3
Element 4 c
Element 5
Element 6 d
Element 7
iVektor1[0] = a
iVektor1[1] =
iVektor1[2] = b
iVektor1[3] =
iVektor1[4] = c
iVektor1[5] =
iVektor1[6] = d
iVektor1[7] =
a
b
c
d
****************getchar and scanf() exempel end*************************
getch() is doing allmost everything correct exept it suck chars in and you
can't se what you have enterd.
Element 0
Element 1
iVektor1[0] = a
iVektor1[1] = s
as
****************getch exempel end*************************
I allso have tryed getcha() it behaivse most 'normal' of them all in this
situation, exept after entering char it just stright to asking for next
element. like fits enter for you...
so back to my question, how can I fix so the user can enter char and press
enter before entering next char
void main(void){
int ctCount;
char/*if I use int works fine*/ iVektor1[8];
printf("Enter 8 characters folowed by Enter\n");
// Mata in element för element
for(ctCount = 0 ; ctCount < 8 ; ctCount++){
printf("Element %d ",ctCount);
scanf("%c/*if I use %d works fine*/",&iVektor1[ctCount]);
}
for(ctCount = 0 ; ctCount < 8 ; ctCount++){
printf("\niVektor1[%d] = %c/*if I use %d works fine*/",
ctCount,iVektor1[ctCount]);
}//slut for
iVektor1[8]='\0';
printf("%s",iVektor1);
--
Thanx in advance
and thanx for reading my post!
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my speling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.
I have strange (well to my enyway) problem the code below works like a
sweiz clock if it used for integers, but if I try to put char in it by
interacting with user, for loop ll doubble jump and insern char in
everyother place in vector. I'am guessing it some kind of problem becouse
when asking after char and press Enter I get 8 bits char en enter, is this
the issue? how to comme arround it?
I have tryed to use getchar() but it behavs in the sameway as scanf(),
Element 0 a
Element 1
Element 2 b
Element 3
Element 4 c
Element 5
Element 6 d
Element 7
iVektor1[0] = a
iVektor1[1] =
iVektor1[2] = b
iVektor1[3] =
iVektor1[4] = c
iVektor1[5] =
iVektor1[6] = d
iVektor1[7] =
a
b
c
d
****************getchar and scanf() exempel end*************************
getch() is doing allmost everything correct exept it suck chars in and you
can't se what you have enterd.
Element 0
Element 1
iVektor1[0] = a
iVektor1[1] = s
as
****************getch exempel end*************************
I allso have tryed getcha() it behaivse most 'normal' of them all in this
situation, exept after entering char it just stright to asking for next
element. like fits enter for you...
so back to my question, how can I fix so the user can enter char and press
enter before entering next char
void main(void){
int ctCount;
char/*if I use int works fine*/ iVektor1[8];
printf("Enter 8 characters folowed by Enter\n");
// Mata in element för element
for(ctCount = 0 ; ctCount < 8 ; ctCount++){
printf("Element %d ",ctCount);
scanf("%c/*if I use %d works fine*/",&iVektor1[ctCount]);
}
for(ctCount = 0 ; ctCount < 8 ; ctCount++){
printf("\niVektor1[%d] = %c/*if I use %d works fine*/",
ctCount,iVektor1[ctCount]);
}//slut for
iVektor1[8]='\0';
printf("%s",iVektor1);
--
Thanx in advance
and thanx for reading my post!
________________________
BTW. I know my english is not best in the word, so please stop bugging me
about my speling. And yes Iam sorry you don't understand what I mean, but
there is no point to yell at me. Have a nice day.