Re: [algogeeks] find the error

2011-09-17 Thread sukran dhawan
get() function ? On Thu, Sep 15, 2011 at 12:14 AM, rahul vatsa vatsa.ra...@gmail.com wrote: ther is no get() function. On Wed, Sep 14, 2011 at 1:55 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: I think there is no problem with the while statement, even if file is not present , it will

[algogeeks] find the error

2011-09-14 Thread ravi maggon
Something like this was asked in written test of Tally. We had to find the cause why this program crased during run time. File *f; int count=0; if(f=fopen(file.txt,r)) { while(f.get()!=EOF) { count++; } } -- Regards Ravi Maggon B.E. CSE, Final Year Thapar University

Re: [algogeeks] find the error

2011-09-14 Thread abhinav gupta
file not closed. On Wed, Sep 14, 2011 at 5:56 PM, ravi maggon maggonr...@gmail.com wrote: Something like this was asked in written test of Tally. We had to find the cause why this program crased during run time. File *f; int count=0; if(f=fopen(file.txt,r)) { while(f.get()!=EOF)

Re: [algogeeks] find the error

2011-09-14 Thread ravi maggon
sorry fclose was also written in the last line. I missed it while asking. On Wed, Sep 14, 2011 at 6:10 PM, abhinav gupta guptaabhinav...@gmail.comwrote: file not closed. On Wed, Sep 14, 2011 at 5:56 PM, ravi maggon maggonr...@gmail.com wrote: Something like this was asked in written test of

Re: [algogeeks] find the error

2011-09-14 Thread JITESH KUMAR
I guess, if file is not found, fopen will return -1. Which will evaluate the statement if(f=fopen(file.txt,r)) as true.. -- *Regards Jitesh Kumar There is only one 'YOU' in this world. You are Unique and Special.* *Don't Ever Forget it.* -- You received this message because you are subscribed

Re: [algogeeks] find the error

2011-09-14 Thread sandeep kumar
if file.txt is not present it gives a seg fault and if the file is present then the problem is with f.get(), use fgetc or fgets etc the program runs without any error *..* * **Regards Sandeep Kumar MTech Computer Science **IIT Madras* Music washes away from the soul the dust of

Re: [algogeeks] find the error

2011-09-14 Thread Puneet Gautam
I think there is no problem with the while statement, even if file is not present , it will create a new file... The problem is with f.get()but dunno what...? On 9/14/11, sandeep kumar sandeep.crazyguy2...@gmail.com wrote: if file.txt is not present it gives a seg fault and if the file is

Re: [algogeeks] find the error

2011-09-14 Thread rahul vatsa
ther is no get() function. On Wed, Sep 14, 2011 at 1:55 PM, Puneet Gautam puneet.nsi...@gmail.comwrote: I think there is no problem with the while statement, even if file is not present , it will create a new file... The problem is with f.get()but dunno what...? On 9/14/11, sandeep

[algogeeks] Find the error..

2011-06-22 Thread Balaji S
What is the wrong in this program main() { char *p,*q; p=(char *)malloc(25); q=(char*) malloc(25); strcpy(p,INDIA ); strcpy(q,hyd); strcat(p,q); printf(%s,p); } -- With Regards, Balaji.S -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To

Re: [algogeeks] Find the error..

2011-06-22 Thread PRITPAL SINGH
What do you expect it to give ? On Wed, Jun 22, 2011 at 4:25 PM, Balaji S balaji.ceg...@gmail.com wrote: What is the wrong in this program main() { char *p,*q; p=(char *)malloc(25); q=(char*) malloc(25); strcpy(p,INDIA ); strcpy(q,hyd); strcat(p,q); printf(%s,p); } -- With

Re: [algogeeks] Find the error..

2011-06-22 Thread PRITPAL SINGH
http://www.ideone.com/pubwV On Wed, Jun 22, 2011 at 4:30 PM, PRITPAL SINGH pritpal2...@gmail.comwrote: What do you expect it to give ? On Wed, Jun 22, 2011 at 4:25 PM, Balaji S balaji.ceg...@gmail.com wrote: What is the wrong in this program main() { char *p,*q; p=(char *)malloc(25);

Re: [algogeeks] Find the error..

2011-06-22 Thread Shachindra A C
the only thing wrong about the program is the memory leak :p On Wed, Jun 22, 2011 at 4:30 PM, PRITPAL SINGH pritpal2...@gmail.comwrote: What do you expect it to give ? On Wed, Jun 22, 2011 at 4:25 PM, Balaji S balaji.ceg...@gmail.com wrote: What is the wrong in this program main() {

Re: [algogeeks] Find the error..

2011-06-22 Thread Balaji S
@pritpal : Refer ques 5 at http://www.youthrocker.com/2011/06/interview-questions-amazon-placement.html @shachindra : wats tat :-o -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Find the error..

2011-06-22 Thread PRITPAL SINGH
@balaji I think memory leak is the only problem with the code. rest is fine On Wed, Jun 22, 2011 at 6:03 PM, Balaji S balaji.ceg...@gmail.com wrote: @pritpal : Refer ques 5 at http://www.youthrocker.com/2011/06/interview-questions-amazon-placement.html @shachindra : wats tat :-o -- You

Re: [algogeeks] Find the error..

2011-06-22 Thread Shachindra A C
@balaji, the memory allocated from the heap using malloc needs to be released before termination of the program. there should be two additional statements as follows: free(p); free(q); On Wed, Jun 22, 2011 at 6:09 PM, PRITPAL SINGH pritpal2...@gmail.comwrote: @balaji I think memory leak is

Re: [algogeeks] Find the error..

2011-06-22 Thread Vishal Thanki
memory leak and memory allocation check, make sure malloc return non-null. On Wed, Jun 22, 2011 at 7:04 PM, Shachindra A C sachindr...@gmail.com wrote: @balaji, the memory allocated from the heap using malloc needs to be released before termination of the program. there should be two additional

Re: [algogeeks] Find the error..

2011-06-22 Thread ankit sambyal
@Balaji : the code given by u compiles and runs successfully in gcc compiler and gives the correct answer i.e. INDIAhyd . What's the problem ?? @Shachindra A C : Which memory leak are you talking about ?? The memory allocated from the heap using malloc need not be released before termination of

Re: [algogeeks] Find the error..

2011-06-22 Thread ankit sambyal
@Vishal : Ya this seems to be correct.. On Wed, Jun 22, 2011 at 7:05 AM, ankit sambyal ankitsamb...@gmail.com wrote: @Balaji : the code given by u compiles and runs successfully in gcc compiler and gives the correct answer i.e.  INDIAhyd . What's the problem ?? @Shachindra A C : Which memory

Re: [algogeeks] Find the error..

2011-06-22 Thread Shachindra A C
As vishal pointed out, checking the return val is missing and it is the programmer's responsibility to free up the memory which he has requested for... On Wed, Jun 22, 2011 at 7:37 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Vishal : Ya this seems to be correct.. On Wed, Jun 22, 2011 at