I can't figure out pointers

I would like to create a sub routine for creating strings to full caps so I can create a menu feature that would be able to distinguish spelled words regardless of capitalization and possibly create small spell check features. Although I do not typically need a routine to specifically index arrays by the use of points to do this. I still can not figure out for the life of me how to pull a value from a pointer through a reference regardless how I cast or anything else.

I originated this task to perform to upper on a string to array conversion but once it was converted to a string it refused to be cast back to a char. Any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <ctype.h>
#include <string.h>
#include <locale>

using namespace std;
    string a;
    char c_f[16] = " ";
    char p = (char) &c_f[0];

int main(){
    getline(cin >> ws, a);
    c_f[0] = (char)a[0];
    cout << c_f[0];
    char b = (char) *p;
    cout << b;
}
... does that compile ?? And if so, how did you do that ?
try the following ...
1
2
3
4
5
6

using namespace std;
    string a;
    char c_f[16] = " "; // I think char c_f[16] = {'\0'} would be fine here, but it should not matter ...
    char *  p = (char * ) &c_f[0]; // NOT char p = (char) &c_f[0];


That will do, i guess ...
The reason is you cast the address of c_f[0] (wich is a NOT a character) into a character.
So p, in case your compiler won't complain, will be a strange thing. And if you pick that value at the address "p" (which is a character in your code) .... well

I can't guess what p will be and i can not try it, because i can not compile the example. But with that little change it should work ... hopefully as intended.



OP: there was an interesting discussion on another board recently about making case insensitive string comparisons which might be of use:

http://cboard.cprogramming.com/cplusplus-programming/171490-making-vector-string-case-insensitive.html
Topic archived. No new replies allowed.