why have u written the code from line #22 to line #26.
Do u think u need them.....?
necrolin commented: Thank you +1
BestJewSinceJC commented: Thanks! Wish I could give you more rep. +4
dkalita 110 Posting Pro in Training
why have u written the code from line #22 to line #26.
Do u think u need them.....?
the function fun() takes a funtion(whose return type is int and with no params) pointer as its argument.
And u are sending main to that funcion.
Thats it.
Read on pointer to function.
That sounds good.
In the 1st iteration it will be 1, in the second n=i+1 = 2 because i==1 now aand so on. But in the later case n will always be 1 because u did n=1.
google for IPC. U wil get a hell lot stuff.
what is the reason that made u feel that the statements
for(n=i+1;n<size1;n++)
and
for(n=1;n<size1;n++)
are equivalent.
How does 1 and i+1 becomes same.
That is the logic and u are changing the whole logic for sorting.
line #57 and #59.
using = instead of == fom comparing
also couldn't get these lines
if(balls[i] = 10) //use ==
{
if(balls[i] = 10) //use ==
///////////////////////////
why the second condition when u already did it......
set some default value to them such as 0
may be u can display using cout as
string str;
char *buf = (char *)&str;
/*u need to know the size of 'str'*/
/*sizeof(str) might work but m not sure about it*/
int i;
for(i=0;i<sizeof(str);i++)/*considering sizeof() works*/
cout<<(unsigned short)*(buf+i)<<",";
I dont know any feature in KDev for displaying the buffer coz I never worked in that. :)
Hope that helps a bit.
The error message is clear enough.
U are defining the function void PlaceYourBet() more than once.
Check your code.
yes you can try something like this
bool isAWin(char &winner)
{
if(isWin('O')) /*considering your players as X and O (change to whatever u are using)*/
{
winner = 'O';
return true;
}
if(isWin('X'))
{
winner = 'X';
return true;
}
winner = ' ';
return false;
}
bool isWin(char player)
{
if(isWinRow(player))
return true;
if(isWinCol(player))
return true;
if(isWinDiag(player))
return true;
return false;
}
bool isWinRow(char player)
{
int r, c;
bool win;
for(r=0;r<rows;r++) /*rows considered to have number of rows*/
{
win = true;
for(c=0;c<cols;c++)/*rows considered to have number of rows*/
{
if(board[r][c] != player)
{
win = false;
break;
}
}
if(win)
return true;
}
return false;
}
bool isWinCol(char player)
{
/* do it yourself*/
}
bool isWinDiag(char player)
{
/*do it yourself*/
}
But, is there any proposed solution to what I'm looking for?
use if() statement and strcmp() function for your purpose.
1> 28 posts and still no code tag
2> Try to practice int main(){} not just main() or void main()
3> Post the exact error that u are getting.
The code seems to be ok I think.
1> finding the mid:
Your function for finding the mid element is good enough. The complexity is O(n/2) not O(n) but anyway O(n/2) is also considered O(n) only when n is very large.
2> mid of even set of data
Its upto you or upto the requirement which will tell which one to select as the mid-element. Sometimes u may take the n/2 th element or sometimes u can take (n/2 +1)th element.
e.g. in the set {1,2,3,4}
U can either take 2 or 3 as the mid-element.
I dont think u can do that.
Its because the console is just a resource and the same resource cannot be shared by more than one process at a time.
When u are doing a read operation the console is reserved for that process and any write operation will only be executed when the read operation is complete and the resource is free.
y=x/10;
10 z=x%10;
11. x=y;
12. printf("%d",z);in the above code,
y=3/10=0 thats o.k but
what is 3%10 ?
how will z becomes 3 as explained by dkalita
It would be better if you read about arithmatic operations in C first.
Thanks a lot. So, is the below code correct.
1. #include<stdio.h>
2. #include<conio.h>
3. void main()
4. {
5. int x,y,z;
6. scanf("%d",&x);
7. while(x>0)
8. {
9. y=x/10;
10 z=x%10;
11. x=y;
12. printf("%d",z);
13. }
14. printf("%d",x);
15. }
Hope u got your answer from Tojan Wong's reply.
I am not ignoring dkalita's solution..
ya, its right and perfect....
but Mr tojan you just try to use this logic in char string "tojan"...
obiasly it will not work...
dkalita had ignored me to use "strlen()" function and told that his given solution is best ....
so, i mean to say only that dkalita's logic will work for only integer numbers...
and our C compilers are giving use ready mate functions to make better and easy programing then why we can't use this..???
hope you got it.....!!!
yep buddy.
You are right.
Its good to use ready made stuffs.
But when it comes to efficiency and all then sometimes its better to build some modules yourself.
That will improve your programming skills.
You will get to learn a lot.
When you feel that you have learned a lot, you will know when to use ready made stuffs and when not to.
It just depends on the requirement soimetimes.
EDIT:
The solution I gave is a generalized one which u can implement in any programming language where there might not be a library method for that.
N.B. And ofcourse my solution is only for integer.
there is an example program
when u divide an integer by an integer u get the result also an integer.
generally when u do 3/2 it should have been 1.5 but since both are integer values u will get the result as 1 not 1.5.
If u want 1.5 u have to typecast either of the operands to float.
there is no sched.c file.
U have to include linux/sched.h file.
I guess u are doing some kernel module....!
U can use the following link to learn how to write and compile a kernel module:
http://tldp.org/LDP/lkmpg/2.6/html/index.html
Format of the task_struct is in the link:
http://www.cems.uwe.ac.uk/~ngunton/foils2/taskstruct.pdf
Ofcourse there are generic ways to make a recursive method non-recursive. Just google for it. U wil get that.
Regarding the use of recursive functions: It is not recommended always because it may lead to stack-overflow and crash of your program if the iterations are large in numbers.
But its a very easy way to some some very typical problems which are a bit difficult to solve using non-recursive functions.
use debugging tool(e.g. gdb) for debugging your code. U wil know where exactly the error occured.
U can post your complete code here.
But I prefer U to find the problem yourself. Just debug it.
what do u expect y to be when x is 3.
y=x/10 = 3/10 = 0. thats it. Hence after printing z (which is now 3).
OK I thought u wrote while(x>0). I ignored that line. Sorry for the misunderstanding.
If it were a while loop then next time x becomes zero and the loop breaks.
BTW I dont understand why u have used if(x>0) that wil consider for only one digit.
U must use a while loop instead.
May be u can get some hint from this thread.
http://www.daniweb.com/forums/thread33551.html
Many of the machine info u can get from the files present in the following folder:
/proc/sys/kernel
best way to do it is
int reverse(int num)
{
int rev = 0;
while(num>0)
{
rev = rev*10 + num%10;
num = num/10;
}
return rev;
}
Thank god there are only 26 alphabets.
If there were 100 u would need to write 100 if statements.
May be u can take some other approach for your problem such as:
write a function like
void removeDuplicate(char *str);
It doesn't necessary that a user wil input a-z. There are many printable characters available.
Implement the above method. If u wanted to do it in C++ u could have used a map of flags such as
map<char, bool> charMap;
When u get a new char in the input string just make an entry as
charMap[myChar] = true; /*that says u have encountered that char*/
If u want to continue with C only u can still do it using an array like
#define MAX_CHAR 100 //whatever the total no. of characters are available
int charEncountered[MAX_CHAR];
//initialize them to 0 (zero)
//use it as
if(charEncountered[myChar]==0)
{
charEncountered[myChar] = 1;
//put it in the new buffer
}
else
{
//duplicate
//ignore it
}
the param to a switch cannot be a string.
It can only be an integer. To achieve what u are trying use if-else statement alongwith strcmp().
use code tag.
Do proper indentation to you code.
Suppose I enter 321
y will become 32
z will become 1
x will be 32It will print first z which is 1
then it will print x which is 32But it should have been 123 ( Reverse of 321)
why wil it print 32.
See the code.
if(x>0)
{
y=x/10;
z=x%10;
x=y;
printf("%d",z);
}
the 32 wil again be processed similarly.
u wil have
y=x/10 i.e. y=32/10 = 3
z=x%10 i.e. z = 32%10 = 2
x=y i.e. x = 3
print z: 2 wil be printed now. AND SO ON untill x>0.
Why have u added the statement:
printf("%d",x);
It wil add an unwanted zero at the end of every reversed number.
line #23:
it should be
cout<<data[(i*cols)+j]<<" ";/*not i*rows*/
its says the character 'a'.
Like we represent a string using double quote, e.g. "test string", we represent a character using single quote, e.g. 'a'.
u are welcome
void f(int** a) //its a pointer to a pointer. The argument to the function f is a pointer to pointer
{
cout << **a; //prints the value stored in a, output is 45
cout << *a; //address of the memory where 45 is stored
cout << &a; //address of variable 'a' (it will come as ***)
}
//I'm OK with main(). I'm including it FYI
int main()
{
int i = 45;
int* ptr = &i;
f(&i);/*u r passing incorrect arg*/
/*passing 'int *' instead of 'int **'*/
/*should have called as: f(&ptr);*/
}
EDIT: correction
line #5: its "int ***" and not simply "***" in the comment.
check the link:
http://tigcc.ticalc.org/doc/comopts.html
(search for ansi in it)
or read the gcc manual (man gcc).
The description is present there.
remove the -ansi option while compilation. Just do
gcc -Wall client.c
Hi, I compiled that file (client) and I am not getting any error . !!!!!!
I used cc compiler and compiled on the following OS
Linux mymachine 2.4.20-28.9.XFS1.3.1smp #1 SMP Mon Jan 5 13:20:15 CST 2004 i686 athlon i386 GNU/Linux
u are doing it in the correct direction.
Go ahead with your code and test it.
May be (not sure) u need to break up your file into smaller blocks for transferring if the file is very large.
yes.
That is iterpreted and processed by the shell which sets the argv and forward to the executable binary file.
I don't think so.
And if there is some way I would love to know it. :)
How to:
1. Buffer output ?
2. Get its size ?
3. Print the buffer ?#include <stdio.h> int main(void) { printf("Tons of printf lines\n"); // 1. Somehow buffer the output up until this point printf("The size of the buffer is: %i\n", SIZEOFBUFFER); // 2. Get and print the size of the buffer. printf("Here is the output:\n\n%s", BUFFER); // 3. Print the buffer. return 0; }
may be something like
#define MAX_BUFFER 1000
char BUFFER[MAX_BUFFER];
BUFFER[0] = '\0';
strcat(BUFFER, toPrint);/*toPrint contains whatever u wanted to print*/
/*but check for the buffer content size because if it exceed MAX_BUFFER u wil get seg fault*/
/*do it for every printf("%s", toPrint)*/
printf("The size of the buffer is: %i\n", strlen(BUFFER)); // 2. Get and print the size of the buffer.
printf("Here is the output:\n\n%s", BUFFER); // 3. Print the buffer.
The function main in myprog will receive a char** argv containing the following strings
"-z", "hello", "-m", "this is a message"
One small correction.
char** argv will contain
"myprog", "-z", "hello", "-m", "this is a message"
So there must be somewhere in a C library a function which takes the command line string and produces the char** argv.
My question for you, C experts, is where is this function and how is it called ?
I guess this part is done by the OS rather than a compiler.
Hi,
I hav heard that it isn't that simple to write a program in linux using c.
Lots of commands n stuff.Please simplify what actually I've got to do to run turbo c++ in my linux laptop as I am a beginner.
I guess U will change your opinion once u start doing programming in Linux.
Linux comes with C compiler by default and u don't need to install any.
Write your source code using any editor u have. Store it with an extension .c.
Now open a terminal. Use the cc command to compile your file as:
$cc <filename.c>
/////that will produce a out file called a.out which is the executable.
to execute that file do:
$./a.out
If u want to specify the executable name then do:
$cc -o <executable name> <filename.c>
e.g.: cc -o test test.c
execute using ./test
U Just need to explore a bit.....................
Adding to crazyboy:
It can be generalized as follows:
expr?expr1:expr2;
MEANS
if(expr)
expr1;
else
expr2;
u have to draw the left side line and right side line in the same loop by printing col number of spaces in between
where is the memory allocation for course::classD.
line #32: allocate memory for classD like u did for course::dept
Just explore this site a bit.
Infix to postfix conversion has been discussed earlier in many threads.
i guess u have not initialized iRowCount and iNoOfCol.
Also note that iRowCount<=MAX_ROW and iNoOfCol<=MAX_COL. Otherwise u will get array outofbound error (or seg fault)
1> 16 posts and yet no code tag
2> U are comparing integer with a node pointer in the following line:
for(i=1; i<currentNode; i++)/*i : integer, currentNode : a pointer..............................ERROR IN HERE*/
{
cout<<i<< getSpatie(currentNode->word)<< currentNode->numTimesAppear<<endl;
/*remaining codes*/
I think u are looking for something like
for(i=1; i<currentNode->numTimesAppear; i++)
{
cout<<i<< getSpatie(currentNode->word)<< currentNode->numTimesAppear<<endl;
/*remaining codes*/
please mark te thread as solved if u think its solved......thanks........n welcome.....
char cmd[100];
strcpy(cmd, "mkdir ");
strcat(cmd, dirName);
system(cmd);
strcpy(cmd, "mv ");
strcat(cmd, fileName);
strcat(cmd, " ");
strcat(cmd, dirName);
strcat(cmd, "/");/********..........CORRECTION IN HERE....*/
strcat(cmd, fileName);
system(cmd);