why doses not this simple function work?

When I run it does not even ask what to write. It just diplays what i had cout when calling it.

OK so the output is nothing. Just Press any key to continue.

how I am calling it is:

char writer();


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
char writer ()
{
     cout << "what do you want to write? Limit within 100 character" << endl;
     char holder[100];
     for (int m=0 ; m < 100 ; m++)
     {
         cin >> holder[m];
     }
     
     ofstream file("biplav.txt");
     
     
     if (file.is_open())
     {
          for (int m=0 ; m < 100 ; m++)
          {
              file << holder[m];
          }
     file.close();
     }
     else
     {
         cout << "Unable to open file" << endl;
     }
     return 0;
}
Last edited on
Show how you are calling the function.
I was thinkin it should look more like 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "stdafx.h"

using namespace std;

int m;
	char holder[];
 char writer(holder[m]);  //
	{
  
     char holder[100];
     for (int m=0 ; m < 100 ; m++)
     {
    
     }
     
     ofstream file("biplav.txt");
     
     
     if (file.is_open())
     {
          for (int m=0 ; m < 100 ; m++)
          {
              file << holder[m];
          }
     file.close();
     }
     else
     {
         cout << "Unable to open file" << endl;
     }
     return 0;
}

int _tmain(int argc, _TCHAR* argv[])

{cout << "what do you want to write? Limit within 100 character" << endl;
	cin >> holder[m]
	
	writer(holder[m])

cout << "You wrote" << holder[m] << end1;

// some kind of pause for user input to exit program
	return 0;
}


but I am gettin errors but visual studio is like pissin me off bc I should be able to "using namspace std; without gettin a syntax error or some other bs pissin me off I could b wrong about the above bc i'm new myself but i'm tryin to help
Last edited on
umm are you sure? because thats in the tutorial(what i have done) just put in function
That would be my best guess, like i said i'm still a newb so..... Hope that helps

o It was already in a function, but it was not called hence not much action.
Last edited on
can anyone else confirm it?
biplav17, nobody can confirm anything, because you haven't posted all of the relevant code yet, nor have you posted what happens when you attempt to run your program.

I can tell you, however, that you're calling a function of type char (which only returns one character, not the string that you might be looking for), and trying to return an int, which is an error in typecasting. In fact, without knowing that you're actually looking for some sort of feedback from the function, which I assume you're not, since you don't send back anything meaningful, the function should be of type void.
Last edited on
Topic archived. No new replies allowed.