C++ question about char variables?
408732
To use the input the way you want... you have know how the c compiler gets the input... all output and input are first transferred from the i&#92;o device to a stream...so the input is  stored in a stream and the program gets its input from this stream...so if the user gives two chars as input... its stored in the stream... and after the program gets a char from the stream...the next char which is in the stream is taken as the next input... to avoid this you can use the function fflush();... this funtion erases the stream...
240615
I am giving the solution in C++ using recursion..\n\n!!\n\n#include<iostream.h>\nvoid printstars(int n)\n{\nfor(int k=0;k<n;k++)\n     cout<<"*";\ncout<<endl;\n}\nvoid print1(int n)\n{\nif(n<=1)\n   printstars(n);\nelse\n   printstars(n-2);\n}\nvoid print2(int m,int n)\n{\nif(m==n)\n   cout<<endl;\nelse \n{\n   printstars(m);\n   print2(m+2,n);\n}\n}\n\nmain()\n{\nint n,m=1;\ncout<<"Enter an odd number n";\ncin>>n;\nprint2(m,n);\nprint1(n);\n}\n\nThis produces the output u needed and also uses recursion.
477862
I can see by looking at it that it won't compile.\nYou don't have semicolons at the end of the lines.\n\nI you put in the semicolons and replace the comma in the for loop with the another semicolon, it will compile and run.\n\nHowever, I don't think that you will get what you expect.\n\nYou use x without initializing it. That means that x will take the value that is already in memeory at that address.\n\nNext you condition your while loop on (R!=R) which is always false, so the while loop never executes.\n\nWhat you will print out is the last value that was left in x which is a location on the stack. \nI'm running MS C++ in debug mode, so it fills in the bytes of x with the value CC so you can recognize it as uninitialized stack memory.\n\nLast, you compute S but never use it.
444754
This sounds like school work, its a fairly simple program. you will probably want to use the cout and cin function which needs you to include iostream.h \n\nsimply use cout to print to screen, ask for input etc. then take the input using cin and store it to a int variable.\n\na good way to do it would be to ask the user what they wish to do, eg subtract, divide and take that operator first, a symbol or a number to show choice. then the next line asks for the numbers to be input.\n\neg:\n\n---------\n\nHello. what do you wish to do:\n1 - subtract\n2 - divide\n3 - etc etc\n\n>\n\n-------------\n\nthen use an if function or maybe a switch to check what their input was and do the artithmatic.\n\nso a very basic prgram may look like this:\nit may have errors i havant checked it.\n\n-----------------\n\n#include <iostream>\n\nint main() \n{\nint number;\n\n    cout << "Hello, input a number" << endl;\n    cin >>number;\n    return 0;\n}\n\n------\n\nEDIT; i re read the req, you might find inputting the selection to a char better, then check the char to see what symbol is stored in it, eg + / -. and maybe use a char array for the number input. simple take the char array, check for the space. split the numbers into 2 and caste then to an int. sounds complicated but it isnt to hard.\n\nsorry about spelling mistakes.
777982
make sure 'a' is defined as a pointer to another variable you've declared. like:\n\n int b = 1;\n int* a = &b;\n\nOtherwise, if you simply declare \n  int* a;\n  *a = 1;\n\n..then you have reserved memory for an address, but not for the contents.  'a' is pointing to a pseudo-random place in memory.\n\n Secondly, printf() of 'a' should return the address you've reserved.  printf() of '*a' should return the 1 as you're expecting.  The most likely reason you're not seeing this is because 'a' is set to (1) - which means it is not a valid pointer.  This can be caused by some compilers in a DEBUG build when a variable goes out of scope.  As in:\n\n  int* a;\n {\n    int b = 1;\n    a = &b;\n  }\n  // 'b' is now out of scope - some compilers will change memory to indicate this during a debug build.  *a is now (0) !\n\n Hope that helps.
952303
Bcoz, the char itself returns the address...\nso no need for using '&' before it...
260093
Here it is:-\n\n/* Convert.cpp */\n/* Display the reverse of the input */\n/* By Senthil */\n\n#include <iostream.h>\n#include <conio.h>\n#include <string.h>\n\nvoid main()\n{\nchar inp[10];\nint cnt = 0, ex = 0;\nclrscr();\n\ncout<<"Enter some characters (max limit 10) : ";\ncin>>inp;\n\ncnt = strlen(inp);\ncnt--;\nfor(ex = 0;ex != cnt;ex++,cnt--)\n{\ninp[ex] = inp[cnt];\n}\ncout<<"The reverse of the string is : "<<inp;\ngetch();\n}
142433
you havn't closed "void determinecost (...)" function with curly braces " } "\n\nin c++, you have to close any block of code with } that has been opened with {
998792
What is (char*) doing there? Simple! It converts int to char for ii and float to char for aa. The compiler doesn't automatically convert int to char or float! (because int is larger then char, and by converting it you loose data, same for float..).\nAnd now refering to the output... It depends on what system this source is compiled, and nevertheless on the compiler you are using! The problem consists in converting an int to a char, and it depends on the compiler how many bytes are allocated when declaring an int! (same for converting float to char)
169151
int\nmain (void)\n{\nfor(i=0;i<10;i++){\nprintf("some thing output here %d", i)\n}\n}
816527
You have a return character leaking over in the input stream from when you make your Choice.  If you change this line\n\ncout << endl << "Your choice=> " << Choice << endl;\n\nto\n      \ncout << endl << "Your choice=> " << Choice << endl;\ncin.ignore(1);\n\nIt will remove the return character.  There's probably a better way to handle this type of problem, but my mind is fuzzy at the moment.\n\nFixing that problem, you are presented with another problem of removing names with spaces in it from your list.  To fix that use\n\ngetline( cin, Value);\n\ninstead of\n\ncin  >> Value;\n\nin your Remove function.  The latter piece of code places a null character at the first space it sees in the input stream which you don't want.  The former correctly places the entire string into Value.
121196
I understand you want to convert A,B,C... to {0,1}, right? then. In C, all strings are character arrays, otherwise collection of characters. by converting each character u can do. as u can see each character both printable and other have a numerical value. it is in a table, ASCII table. Here the code\n----------\nvoid binary(char ch)\n{  if(ch>0) binary(ch/2);\n   printf("%d",ch%2);\n}\nvoid toBinary(char*text)\n{  for(i=0;text[i]!='&#92;0';i++)\n   {  binary(test[i]);\n      printf("&#92;n");\n   }\n}\n----------\n\ni hope these two functions helps you.....\ngood luck.
496646
Pointer to a reference ?? You are basically passing the address the refence is stored at. You could have done \nint someMethod(BaseClass* myVariable) as well but I think this is substandard code. While most compilers would compile it, you are "not supposed" to write things like that.\nAlternatively, you could have done:\nint someMethod( BaseClass& myVariable )\n{\n   BaseClass* p=&myVariable;\n}\n\nHowever references are const pointers so assigning it in that fassion to non const pointer would break the constantness of the reference and result in compilation error. Thats why you do *&.
483781
There are two cases here. The difference between the two case is constructors called are different.\n\nCase 1:     \nString s = "smitha";\nThe above code is equivalent to:\n\nchar data[] = {'s', 'm', 'i', 't', 'h', 'a'};\nString s = new String(data);\nHere the constructor called is: public String(char[] data)\n\nCase 2:\nString s = new String("smitha");\nHere the constructor called is: public String(String str)
1008669
sizeof doesnt give the length of what you actually have, its gives the size of how big the variable has been declared to be . . .\n\nsizeof will return the number of bytes reserved for a variable or data type. \n\nThe following code shows sizeof returning the length of a data type. \n\n\n        /* How big is an int? expect an answer of 4. */\n\nmain()\n {\n   printf("%d &#92;n", sizeof(int));\n        }\n\n \n\n\nsizeof will also return the number of bytes reserved for a structure. \n\n\n        /* Will print 8 on most machines. */\n\n        main()\n{\n  struct \n  {\n    int a;\n    int b;\n  } TwoInts;\n\nprintf("%d &#92;n", sizeof(TwoInts));\n}\n\n\n \n\n\nFinally, sizeof will return the length of a variable. \n\n\nmain()\n{\n  char String[20];\n  \n  printf ("%d &#92;n", sizeof String);\n   printf ("%d &#92;n", sizeof (String));\n        }\n\n\n \n\n\nIn the example above I have printed the size of 'String' twice. This is to show that when dealing with variables, the brackets are optional. I recommend that you always place the brackets around the sizeof argument.
490941
Delete (when used with a pointer) destroys what the pointer points to (e.g., pointer is still there, and can point to something else).  Destroy destroys the pointer/object itself.\n\nFor instance:\n\nchar** charArrayPtr = new char[50];\ndelete charArrayPtr;\ncharArrayPtr = NULL;\ncharArrayPtr = new char[25];\n\nBut if you did\n\ndestroy(charArrayPtr);\n\nyou couldn't use charArrayPtr anymore.\n\nReally, no real need to call destroy explicitly, for the most part.
635623
I don't know C++. But You can do it by sending  the text in to prn folder. Same thig you can do it in DOS type a.txt >prn