Re: fscanf

From: Date: Tue, 13 Mar 2001 02:37:28 +0000
Subject: Re: fscanf
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-43597@lists.php.net to get a copy of this message
----- Original Message ----- From: "Kubol" <kubol@kormoran.trzepak.pl> To: <php-general@lists.php.net> Sent: Tuesday, March 13, 2001 12:48 AM Subject: Re: [PHP] fscanf > 01-03-13 05:00:01, "Yasuo Ohgaki" <yohgaki@hotmial.com> wrote: > > >I think fscanf() is line oriented in C, isn't it? (I haven't used fscanf() for a > >long time, I'm not 100% sure w/o reference.) > no, i'm sure in c fscanf reads the next string available, not first string in next line > >Your $buffer should only have "lenin". > i agree. in first iteration buffer should contain "lenin", but in second the content should be "lives", not "forever", > but is "forever" and i dont > know why and i'm angry about it :-) > >while (fscanf($file,"%s %s",$buf1,buf2)) > >You should get "lives" in $buf2. > i agree again, but i dont know how many stings do i have in one line. therefore i cant use > fscanf($file,"n*%s",n*some_variables); > besides it looks terrible... :-) Now I understand why you are wondering. In C, you can get "words" in file with your code, but not in PHP. fscanf() between C and PHP is not identical when I made a simple test codes for both. It seems PHP's fscanf() advances file pointer to end of line while C's fscanf() must be done by programmers like fscanf(fp,"%*[^\n]"). In most cases, programmers want to move file pointer to the end of line. Maybe that's why PHP's fscanf() does this. We cannot expect PHP functions works just like C/C++/Java since it is different languange even is name of the function is the same. I guess what you want to do is getting all words from a file using fscanf(), but it seems it is not possible with PHP's fscanf(). (Or is it a bug? Anyone?) Functions that have the same name in C better to be behaive just like C in PHP for C programmers. (but may not be good for non-C programmers.) I'm relatively new to PHP, so I don't know historical reason why some functions does not behaive like C. I see a lot of differences PHP and C, I think this is the way it is. How about a start new thread if you still curious about fscanf() behaviour? Someone may be able to give better explaination. Regards, -- Yasuo Ohgaki > regards, > jakub zytka > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#43597) next »