trouble passing char arrays

So i have this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 char fname[16];
 char oname[16];

//then i get input from the user

in = 5;
            int now = 0;
            while((char)inputs[in] != ' ')
            {  
                  fname[now] = inputs[in];  
                  in++;     
                  now++;    
            }
            for(int i = now - 1; i < 16; i++)
            {
                    fname[now] = '\0';
            }
            cout << fname << endl;
            in++;
            now = 0;
            while((char)inputs[in] != ' ')
            {
                  oname[now] = inputs[in];       
                  now++;
                  in++;    
            }
            cout << oname << endl;

// it prints out fine here but when it goes out here 
cpin(fname,oname);


1
2
3
4
5
6
7
void cpin(char * filename, char * name)  
{    
     cout << filename << endl;
     int two;
     cin >> two;

//it prints random gibberish here 



Im on a tight schedule :P i thought this would be the easy part of the project :(

It was working when i just did :

cpin("string one", "string two");

before..
Last edited on
Does the debugger shows something in the 'filename'.
i honestly never used the debugger and am not sure how to :P im on dev++

but i would guess nothing....
aah.. i haven't used dev++ but I think concept of debugger is the same.

What you can do is, look for a watch window in your debugger (if its a GUI debugger) and add watch on filename and fname.

Now when you call this function,

cpin(fname,oname);

see the value of fname in the watch window.

Now when the code enters the function, see the value of filename. Now if the debugger shows wrong value or garbage value of fname, this means you are not passing a correct value to cpin and its showing garbage. let us know what are your findings.
Last edited on
These links may help you knowing how to debug your code in dev c++

http://www.uniqueness-template.com/devcpp/
http://www.wxwidgets.org/docs/tutorials/devcpp.htm
Cool thanks for getting me to use that tool its nice lol

i found the error ... now i got new errors yay lol
That's the way you learn.
enjoy your programming. :)
Topic archived. No new replies allowed.