Re: [algogeeks] C o/p adobe

2012-11-15 Thread Rahul Kumar Dubey
@rahulsharma
 file1.c

#include
extern int i;// defintion provided in this file itself
extern int j; // definition provided in file2
void next()
{
++i;
other();
}
int main()
{
++i;
printf("%d\n",j);
printf("%d\n",i);
   next();
}
int i=3;

// end of file1.c

file2.c
extern int i; // declaration of i as extern
int j=10; // j defined in file2 here which was declared as extern in file 1
void other()
{
++i;
printf("%d\n",i);
}
// end of file2.c

compile both file together
as
rahul@rahul:~gcc file1.c file2.c
rahul@rahul:~./a.out
you will get the required output





On Fri, Nov 16, 2012 at 8:27 AM, Neeraj Gangwar wrote:

> That's why you are getting the error. You have to compile both the files
> together. Search on google. I don't use dev c++.
>
> *Neeraj Gangwar*
> B.Tech. IV Year
> Electronics and Communication IDD
> Indian Institute of Technology Roorkee
> Contact No. : +91 9897073730
>
>
> On Thu, Nov 15, 2012 at 11:32 PM, rahul sharma wrote:
>
>>  No...individually...dev cpp..how to compile both together???
>>
>>
>> On Thu, Nov 15, 2012 at 9:26 PM, Neeraj Gangwar 
>> wrote:
>>
>>> Which compiler are you using ? Are you compiling both the files together
>>> ?
>>>
>>> *Neeraj Gangwar*
>>> B.Tech. IV Year
>>> Electronics and Communication IDD
>>> Indian Institute of Technology Roorkee
>>> Contact No. : +91 9897073730
>>>
>>>
>>>
>>> On Thu, Nov 15, 2012 at 9:10 PM, rahul sharma 
>>> wrote:
>>>
>>>> but how can i use extern..if i simply declare a variable in file1 as
>>>> int j and try to use in file2 with extern then it shows that j nit
>>>> defined..how cum file2 knows in which file j is definedfor e.g if i use
>>>> extern in file it means that this variable/fxn is defined somewhr else.then
>>>> what are those files in which it searches this variable definition..i m
>>>> getting errorplese give me 2 files in which one files defines variable
>>>> and other uses using extern.its not working for me
>>>>
>>>> On Thu, Nov 15, 2012 at 12:08 PM, Rahul Kumar Dubey 
>>>> wrote:
>>>>
>>>>> @rahul it will compile perfectly well . note that you have declared j
>>>>> in file 1 as extern and used it and have not provided its definition any
>>>>> where
>>>>> so getting compile error.
>>>>> as far as functions are concerned they are external by defaullt as
>>>>> specified by @shobhit
>>>>>
>>>>> i am attaching your corrected code which runs fine ...
>>>>> file1.c
>>>>>
>>>>>
>>>>> #include
>>>>> extern int i;
>>>>> //extern int j; // provide a declaration for this
>>>>> void next(void);
>>>>>
>>>>> int main()
>>>>> {
>>>>> ++i;
>>>>> printf("%d\n",i);
>>>>>
>>>>> next();
>>>>> getchar();
>>>>> }
>>>>> int i=3;
>>>>> void next()
>>>>> {
>>>>> ++i;
>>>>> printf("%d\n",i);
>>>>> //printf("%d",j); // since no defintion provided so getting error
>>>>> other();
>>>>> }
>>>>>
>>>>> file2.c
>>>>>
>>>>>
>>>>> extern int i;
>>>>> void other()
>>>>> {
>>>>> ++i;
>>>>> printf("%d\n",i);
>>>>> }
>>>>>
>>>>> if you want to use j u need to provide defintion either in file 1 or
>>>>> file 2
>>>>> output:
>>>>> 4
>>>>> 5
>>>>> 6
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Wed, Oct 24, 2012 at 10:56 PM, rahul sharma <
>>>>> rahul23111...@gmail.com> wrote:
>>>>>
>>>>>> can nyone provide me dummy code of how exactly to use extern in c..
>>>>>> in dev environment
>>>>>>
>>>>>> when i declare int i in one fyl
>>>>>> and try use use with extern int i in another then it doesnt
>>>>>> compile..plz coment
>>>>>>
>>>>>>
>>>>>> On Wed, Oct 24, 2012 at 9:58 PM, rahul sharma <
>>>>>> rahul23111...@gmail.co

Re: [algogeeks] time complexity of gcd euclid algo(recursive)

2012-11-15 Thread Rahul Kumar Dubey
The complexity is O(h^2) where h is the number of digits in the smaller
number *m* in base 10.


On Tue, Nov 13, 2012 at 3:34 PM, Shruti Gupta wrote:

> hi
>
> Can anyone help me find out the time complexity of recursive gcd algorithm
> (using euclid's algo)
> i.e. for the following program :
>
> int gcd(int n,int m) //given n>m
> {
>if(n%m==0)
>return m;
>else
> return gcd(m,n%m);
>
> }
>
> i think the soln is lg(a*b) but have no idea how..
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: Printing all inversions in an array

2012-11-14 Thread Rahul Kumar Dubey
@carl barbon
if in worst case to print all inversion it takes O(n^2) why to use merge
sort ot BIT , simply use insertion sort ..


On Wed, Oct 24, 2012 at 12:03 AM, Dipit Grover wrote:

> ^ Exactly!
>
> Dipit Grover
> B.Tech in Computer Science and Engineering - lVth year
> IIT Roorkee, India
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] C o/p adobe

2012-11-14 Thread Rahul Kumar Dubey
@rahul it will compile perfectly well . note that you have declared j in
file 1 as extern and used it and have not provided its definition any where
so getting compile error.
as far as functions are concerned they are external by defaullt as
specified by @shobhit

i am attaching your corrected code which runs fine ...
file1.c

#include
extern int i;
//extern int j; // provide a declaration for this
void next(void);

int main()
{
++i;
printf("%d\n",i);
next();
getchar();
}
int i=3;
void next()
{
++i;
printf("%d\n",i);
//printf("%d",j); // since no defintion provided so getting error
other();
}

file2.c

extern int i;
void other()
{
++i;
printf("%d\n",i);
}

if you want to use j u need to provide defintion either in file 1 or file 2
output:
4
5
6




On Wed, Oct 24, 2012 at 10:56 PM, rahul sharma wrote:

> can nyone provide me dummy code of how exactly to use extern in c..
> in dev environment
>
> when i declare int i in one fyl
> and try use use with extern int i in another then it doesnt compile..plz
> coment
>
>
> On Wed, Oct 24, 2012 at 9:58 PM, rahul sharma wrote:
>
>> Then why its not running?
>>
>>
>> On Wed, Oct 24, 2012 at 6:50 PM, SHOBHIT GUPTA <
>> shobhitgupta1...@gmail.com> wrote:
>>
>>> http://www.geeksforgeeks.org/archives/840
>>>
>>> By default, the declaration and definition of a C function have “extern”
>>> prepended with them. It means even though we don’t use extern with the
>>> declaration/definition of C functions, it is present there. For example,
>>> when we write.
>>>
>>> int foo(int arg1, char arg2);
>>>
>>> There’s an extern present in the beginning which is hidden and the
>>> compiler treats it as below.
>>>
>>> extern int foo(int arg1, char arg2);
>>>
>>>
>>> On Wed, Oct 24, 2012 at 4:40 PM, rahul sharma 
>>> wrote:
>>>
>>>> Pleaase reply with sol as asp
>>>>
>>>> Fille 1:
>>>> #include
>>>> extern int i;
>>>>
>>>> extern int j;
>>>> void next(void);
>>>> int main()
>>>> {
>>>> ++i;
>>>> printf("%d",i);
>>>> next();
>>>> getchar();
>>>> }
>>>> int i=3;
>>>> void next()
>>>> {
>>>>  ++i;
>>>>  printf("%d",i);
>>>>  printf("%d",j);
>>>> other();
>>>>  }
>>>> File 2:
>>>> extern int i;
>>>>
>>>> void other()
>>>> {
>>>>  ++i;
>>>> printf("%d",i)'
>>>> }
>>>>
>>>> How cum file 1 knows what is other();as we havnet define with
>>>> extern void other();
>>>> it should be error
>>>> but when i include the statemetn extern void other,then also it shows??
>>>> pls provide me o/p of this questiona nd also tell how use use variable
>>>> of one file in other as simply writing extern in a is not accesing global a
>>>> of other file
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] using name space std

2012-11-14 Thread Rahul Kumar Dubey
"using namespace std" --> it specify that we want to use whole namespace
named*  std .*

In  std namespace varous objects like cout, cin ,endl etc are define
if we donot  use std namespace then we have to explicitly specify name
namespace in which particular objects are defined
eg. std::cout<<"hello world ";
  std::cin>>x; etc *
for more deatils about namespaces read chapter 10 part 1 (thinking in C++
by bruceckel , very nice explanation )
*


On Tue, Oct 9, 2012 at 8:52 PM, rishabh singh yadav <
rishirocker.sing...@gmail.com> wrote:

>  namespaces allows us to group a set of global classes, objects and/or
> functions under a name. If you specify *using namespace std* then you
> don't have to put *std::* throughout your code.
>
>
> On Tue, Oct 9, 2012 at 7:46 PM, rahul sharma wrote:
>
>> That i know..please tell me its use and need
>>
>>
>> On Tue, Oct 9, 2012 at 12:05 AM, Abhishek Patro wrote:
>>
>>> if u have seen the iostream file then it begins like this:-
>>>
>>> #include 
>>> #include 
>>> #include 
>>> *
>>> *
>>> *namespace std *
>>> {
>>>   /**
>>>*  @name Standard Stream Objects
>>>*
>>>*  The <iostream> header declares the eight standard stream
>>>*  objects.  For other declarations, see
>>>*  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#10 and
>>> the
>>>*  @link s27_2_iosfwd I/O forward declarations @endlink
>>>*
>>>*  They are required by default to cooperate with the global C
>>> library's
>>>*  @c FILE streams, and to be available during program startup and
>>>*  termination.  For more information, see the HOWTO linked to above.
>>>   */
>>>   //@{
>>>   extern istream cin; ///< Linked to standard input
>>>   extern ostream cout; ///< Linked to standard output
>>>   extern ostream cerr; ///< Linked to standard error (unbuffered)
>>>
>>> The new implementation is done in C# format. So we use the term "using"
>>> to include the iostream "package".
>>>
>>>
>>>
>>> On Tue, Oct 9, 2012 at 12:01 AM, rahul sharma 
>>> wrote:
>>>
>>>> using name space std
>>>>
>>>> Please explain about this
>>>> thnx
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> Abhishek Patro
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Advice needed

2012-11-14 Thread Rahul Kumar Dubey
modern C does suppport bool
u need to include
*#include *
header
it will work fine as in C++



On Sat, Oct 27, 2012 at 3:21 AM, rahul sharma wrote:

> There is question asked like
> O/p of following in C(32 bit OS)
> #include 
>  #include
> using namespace std;
>
>
> bool IsEqual(char * a)
> {
> printf("abc");
> return true;
> }
>
> int main()
> {
> char str[30];
> printf("%d",sizeof(sizeof(IsEqual(str;
> getchar();
> return 0;
> }
> I run with .cppi know o/p and all in c++...but c doesn't support
> bool.so what should i write in answer as it is asked in written..so wat
> should be writen
>
> 4 i.e the answer in c++ or should i write that c doesn't support bool
>
> plez comment
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] longest palindrome in a string size 2*10^4

2012-09-23 Thread Rahul Kumar Dubey
 *Manacher's algorithm *
*
*
*Its a famous algorithm for finding longest palindrome in a string in O(n)*
*have a look at it on internet ...*
*http://www.leetcode.com/2011/11/longest-palindromic-substring-part-ii.html*
see if it can help you ..

On Sun, Sep 23, 2012 at 5:29 PM, Navin Kumar wrote:

> " *Ukkonen's algorithm* is a linear-time, online 
> algorithm<http://en.wikipedia.org/wiki/Online_algorithm>for constructing 
> suffix
> trees <http://en.wikipedia.org/wiki/Suffix_tree>, proposed by Esko 
> Ukkonen<http://en.wikipedia.org/w/index.php?title=Esko_Ukkonen&action=edit&redlink=1>in
>  1995"
>
> source: wikipedia
>
>
> On Sun, Sep 23, 2012 at 5:08 PM, Navin Kumar wrote:
>
>> Build a common suffix tree for the given string and for its reverse. Then
>> take out the string ending at maximum depth at a common node. Time
>> complexity would be linear.
>>
>> On Sat, Sep 22, 2012 at 5:33 PM, Aditya Raman > > wrote:
>>
>>> Hello everybody,
>>> I need to find a way of finding the longest palindrome in a very very
>>> long string (n<=2) . a linear time algo is expected. help me out
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/algogeeks/-/JdXOBU9fu34J.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] explain the ouput

2012-09-02 Thread Rahul Kumar Dubey
@Rajat Dubey

Actually C forbids the use of sizeof() operator to a function  name .(you
can see the warning using "gcc -pedantic" option of gcc )

so by writing
printf("%d",sizeof(fn) );  // u r trying to get the size of function "fn"
which in no way legal .
and output 1 is compiler dependent .

compile above program with g++ (that is in C++ )  you will get Error as it
has been made illegal in c++ now. and applyiong ""sizeof " to an expression
of funtion type is illegal.

// but printf("%d\n",sizeof(fn())); here its the "sizeof " return value of
function call

On Sun, Sep 2, 2012 at 11:12 AM, RAJAT DUBEY wrote:

> @Rahul kumar Dubey
>
> #include
> double fn(char *a , int b , char c)
> {
> return (1.1);
> }
>
> int main()
> {
> int it = 2;
> char ct = 'c';
> char a[30];
> printf("%d\n",(sizeof(fn)));
> }
>
> why it is always giving output as 1 irrespective of the return type of
> function ??
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] explain the ouput

2012-09-01 Thread Rahul Kumar Dubey
since the function fn() is returning "bool"(here "true " which is of one
byte ) value whose size is 1 byte in C
so your output is showing  1 .

if you change the return type of your function ..say "int " it will print 4
byte (size of integer on your machine ).or say double it will print 8 byte
(size of double on your machine )



On Fri, Aug 31, 2012 at 9:25 PM, Rahul Kumar Patle <
patlerahulku...@gmail.com> wrote:

> #include
> #include
>
> bool fn(char *a , int b , char c)
> {
> return true;
> }
>
> int main()
> {
> int it = 2;
> char ct = 'c';
> char a[30];
> printf("%d\n",(sizeof(fn(a , it , ct;
> }
>
> in gcc 32 bit compiler the above code is always printing 1 even if i
> change the no of argument in fn()
> why?? pls explain..
>
>
>
> --
> Thanks and Regards:
> Rahul Kumar 
> Patle<http://www.linkedin.com/profile/view?id=106245716&trk=tab_pro>
> M.Tech, School of Information Technology
> Indian Institute of Technology, Kharagpur-721302, 
> India<http://www.iitkgp.ac.in/>
> Mobile No: +91-8798049298, +91-9424738542
> Alternate Email: rahulkumarpa...@hotmail.com
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] file handle

2012-08-18 Thread Rahul Kumar Dubey
It is because "fputc()" does not  writes to file directly . All contents
remain in buffer  and as soon as fclose()
is called for that file pointer, buffer content is flushed  to file . so
the file pointer which is closed  last
will overwrite finally  to the file  .
in this case fp2's buffer content will be flushed  last so it will be in
file.
on interchanging two statements "fp1's " buffer content will be flushed
last so it will be in file .

On Sat, Aug 18, 2012 at 5:09 PM, Ratan  wrote:

> #include
> main()
> {
> FILE *fp1,*fp2;
> fp1=fopen("one","w");
> fp2=fopen("one","w");
> fputc('A',fp1);
> fputc('B',fp2);
> fclose(fp1);   // stmt 1
> fclose(fp2);   // stmt 2
> }
>
>
>
> on interchanging the stmt 1 and stmt 2 content of file "one" is also
> changed. how does this happen ... as becauz i am just reversing
> the file closing handle that has nothing to do with writng to the file
> as the file has already been written by fputc() function 
> kindly clarify my confusion..
>
> --
> --
> Ratan | Final Year | Information Technology | NIT ALLAHABAD
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*RAHUL KUMAR DUBEY*
*BTech-3rd  year *
*Computer Science &Engineering *
*Motilal Nehru National Institute Of Technology*
*Allahabad[211004],UP.*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.