User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 391,973 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,188 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser:

add text in the c functions.plz help me

Join Date: Feb 2008
Location: Seattle
Posts: 699
Reputation: jephthah is a jewel in the rough jephthah is a jewel in the rough jephthah is a jewel in the rough 
Rep Power: 4
Solved Threads: 45
jephthah's Avatar
jephthah jephthah is offline Offline
Practically a Master Poster

Re: add text in the c functions.plz help me

  #11  
Mar 26th, 2008
1) i noticed in your earlier code you were using = when you should have been using ==

2) you also had a do statement without a corresponding while condition. avoid do/while's for this and other reasons. you should stick with "while" loops unless you have compelling reason to use "do/while"

3) you should not be "return"-ing in the "else" statement.

4) you should not attempt to define the end of a function by the appearance of "return"... besides the fact that void types do not return a value, a function can have any number of return statements.

otherwise, this sort of works in a basic sense:

  1. use strict;
  2.  
  3. my $openCount;
  4. my $closeCount;
  5. my $foundReturn;
  6. my $myCfile;
  7.  
  8. die "usage: perl $0 <filename>\n"
  9. if (!($ARGV[0]));
  10.  
  11. die "file: <",$ARGV[0],"> does not exist\n"
  12. if (! -e ($myCfile = $ARGV[0]));
  13.  
  14. open(fp,$myCfile);
  15. open(writeme,">output.txt");
  16.  
  17. print "reading <",$myCfile,"> ...\n";
  18.  
  19. $openCount = $closeCount = $foundReturn = 0;
  20. while(<fp>)
  21. {
  22. if ($_ =~ /return/) {
  23. print "hey am inside return if\n";
  24. $foundReturn=1;
  25. }
  26. elsif(($_ =~ /^\{/) || ($_ =~ /\{$/)) {
  27. $openCount++;
  28. print "openCount1=", $openCount ,"\n";
  29. }
  30. elsif(($_ =~ /^\}/) || ($_=~ /\}$/ )) {
  31. $closeCount++;
  32. print "closeCount=", $closeCount,"\n";
  33. }
  34. if($openCount==$closeCount) {
  35. print "count is equal\n";
  36. }
  37. }
you STILL have the problem that if a brace is both preceded and followed by any combination of whitespace, comments, or additional code -- which is a VERY likely prospect -- your counting code will become immediately and irretreivably lost.

for instance:
  1. int main (int argc, char *argv[])
  2. {
  3. unsigned *tempString, *tempPtr;
  4. unsigned i=0, opers=0, ptr=0, key;
  5. FILE *fp;
  6. typedef struct Operator_s {
  7. char Name[26];
  8. char Oin[11];
  9. char Password[16];
  10. } Operator_t;
Last edited by jephthah : Mar 26th, 2008 at 5:28 pm.
Reply With Quote  
All times are GMT -4. The time now is 9:25 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC