int to char / char to int 
Author Message
 int to char / char to int

how is it that this selection sort code works? the code is written
fine and should work. grades is a char array that is passed into the
routine. my question is grades is an array of CHARACTERS! and this
still works fine. i would expect an error at the line with the "**"
next to it, because i thought that something like this: "MinValue =
grades[Index];" would give you an error if "MinValue" was a int type
(which it is in my program) and "Array" is declared a an array of
characters. doesn't grades[Index] give you the value of that index in
array? which is a character. how/why is that assignment allowed?
when i try it with an array of strings i get the expected error, can
someone explain why i get it with string arrays and not with character
arrays?

  int StartScan, MinIndex, MinValue;
  cout << "in SelectionSort" <<endl;
  for(StartScan = 0; StartScan < (count-1); StartScan++)
  {
    MinIndex = StartScan;
    MinValue = grades[StartScan];
    for(int Index = StartScan + 1; Index < count; Index++)
    {
      if (grades[Index] < MinValue)
      {
        MinValue = grades[Index]; **
        MinIndex = Index;
      }
    }
    grades[MinIndex] = grades[StartScan];
    grades[StartScan] = MinValue;
  }



Wed, 16 Nov 2005 04:35:07 GMT  
 int to char / char to int

Quote:
>   int StartScan, MinIndex, MinValue;
>   cout << "in SelectionSort" <<endl;

- The 'shift left' operator doesn't work with strings.
- cout is not defined
- endl is not defined

Please fix your code, or go to


if you are talking another language.

--
-ed- emdel at noos.fr
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-library: http://www.dinkumware.com/htm_cl/index.html
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
                          -- Jerry Coffin in a.l.c.c++



Wed, 16 Nov 2005 04:48:02 GMT  
 int to char / char to int

Quote:

> how is it that this selection sort code works? the code is written
> fine and should work. grades is a char array that is passed into the
> routine. my question is grades is an array of CHARACTERS! and this
> still works fine. i would expect an error at the line with the "**"
> next to it, because i thought that something like this: "MinValue =
> grades[Index];" would give you an error if "MinValue" was a int type
> (which it is in my program) and "Array" is declared a an array of
> characters. doesn't grades[Index] give you the value of that index in
> array? which is a character. how/why is that assignment allowed?
> when i try it with an array of strings i get the expected error, can
> someone explain why i get it with string arrays and not with character
> arrays?

>   int StartScan, MinIndex, MinValue;
>   cout << "in SelectionSort" <<endl;

This is C++. In the future, post your questions to comp.lang.c++ or
write your program in C.

Quote:
>         MinValue = grades[Index]; **

The char type is an integral type. Assignment to int is ok. It's likely
not correct in this case. What are you trying to do?

Brian Rodenborn



Wed, 16 Nov 2005 05:20:29 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. conversion int to char, char to int ?????

2. char to int, int to char...

3. char *fnpars(const char *fn, int p, int v)

4. int gethostname(char FAR* name, int len)

5. int main( int argc, char *argv[] )

6. scaning a char and outputing char, int, float??

7. char *strchr(const char *, int) ??!!!

8. int compress(char *buffer, char *output);

9. int func(int) versus int func(int *) efficacy.

10. CMap <char *, char *, int, int> is not working

11. URGENT: int func( int t, int k, char s[t][k] ) right ?

12. int std::system(const char*) function

 

 
Powered by phpBB® Forum Software