@abhinav
Although my approach works you might want to look at hype261's answer as well since for a stack having a large number of items, my approach would be very inefficient. :)
User Profile
Collapse
-
Hi Donbock,
My thinking was as follows:
We have to implement the Push and Pop functionality of a stack using the Enqueue and Dequeue functionality of a queue. Here's what I thought could be done:
1. Push:
Will be same as an enqueue operation on a queue.
2. Pop:
Dequeue n-1 (n being the total number of items in the queue) number of items from the queue and enqueue...Leave a comment:
-
I think you can implement a stack using just one queue. You can use the enqueue/dequeue functions of the queue to implement the push/pop functions of the stack.Leave a comment:
-
In line 22 you are printing the address and not the value.
Change this:
Code:printf("%d\t",&arr[i]);
Code:printf("%d\t",arr[i]);
Leave a comment:
-
Hello all! :D
Sorry for the delay in replying, too much work in office. :'(
Oralloy you were spot on with your first suggestion about opening the file in binary mode. When I was using fopen to create the file, i *was* using the "b" flag to open it in binary mode, and that was the reason why I could open it in IrfanView.
The reason for the file not opening in Windows Photo Viewer was actually a pretty...Leave a comment:
-
How to recieve a jpg from server using socket programming?
Hi all,
I have a small problem.
I am trying to download a JPG image from a server using C socket programming.
I use the following to "recv" the byte stream and store it into a file I call "test.jpg".
Code:int fp = open("c:\\test.jpg", O_RDWR|O_CREAT); /* set up the socket connection */ while(recvdata != 0){ recvdata = recv(sockfd,
-
Right here: http://dev.mysql.com/doc/refman/5.1/...pe-string.html
Im working on Sun Solaris and the mysql_real_esca pe_string you talked about does not work.
So any suggestions now?
-Sid...Leave a comment:
-
weaknessforcats that was a wonderful tut. I was actually referring to the solution given by Banfa, which is nothing but a solution to the problem of not being able to "return" string.
:O)
@unauthorized
Thanks a lot for telling about the alternate way of doing this although I gotta admit double pointers make me a little woozy! :p Deferring implementation until coding God-mode is acquired. :O)...Leave a comment:
-
mysql_real_escape_string wrapper problem!
Hey all,
I'm stuck with the following:
The mysql_real_esca pe_string(conn, to, from, strlen(from)) function does not return the escaped string. So how can I go about writing a wrapper for it so that it RETURNS the 'to' string which in turn helps me fill out a query in the following manner using sprintf:
Code:unescaped_query = "INSERT into MYTABLE values ('%s', '%s')"; sprintf(escaped_query, unescaped_query,
-
Thanks to you Mr.Banfa I got my code working after incorporating the above suggestions. I'm thankful to you for telling me a more efficient way of doing this.
Thanks to Mr.JoshAH as well.
I guess this question really boils down to the solution for returning a char array from a function. :p
Be back with more queries as I learn.
-Sid...Leave a comment:
-
-
Changing the size of an array passed to a function problem!
Hi all,
I have the following scenario:
Code:int main() { char a[] = "Hello"; printf("Modified string: %s\n", modify_str(a)); } char *modify_str(char *b) { /* Insert a '+' after every letter in the string */ /* "Hello" becomes "H+e+l+l+o+" */ return b; }
-
When should special characers be escaped inside strings?
Hi all. I picked up the following code example from the php manual:
Code:$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') OR die(mysql_error()); // Query $query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'", mysql_real_escape_string($user), mysql_real_escape_string($password));
Last edited by Atli; May 18 '09, 07:07 PM. Reason: Moved to the PHP forum, and the title cleaned up a bit. -
Thank you Mr.Banfa for your expert comments. :O) I'll try the hash method as well just for fun.
Thanks again,
Sid
:O)...Leave a comment:
-
Query regarding optimization of my code
Hi all!
I have a txt file that has some strings in the following format:
TAG=MyString
Eg:
Code:FRUIT=I like mangoes CARS=I like red cars . . . PUSHUPS=I can do a zillion non-stop
Code:#include<stdio.h>
-
ooooh! That's a great way of dealing with malloc. I'm glad I posted my query here. Got to learn new things.
Thank you Mr.Donbock.
:O)
Sid...Leave a comment:
-
Thank you Mr.Donbock for your informative reply. :)
I actually did not intend to alter the string. So going by your word I used the 1st approach. Thank you for letting me know how this works. The malloc'ing of extra memory was just because I was too lazy to count the number of chars in "Hello World!'. :p
Thanks again Mr.Donbok.
Sid...Leave a comment:
-
Query about strings and pointers
Hi all! I have the following code:
Code:typedef struct A { char* string; }A; //Function prototype void fill_up_A(A* a); int main() { A var_A; fill_up_A( &var_A); printf("String is : %s", var_A.string); return 1; } //Function definition void fill_up_A(A* a) {
No activity results to display
Show More
Leave a comment: