| | |
program in c
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
| View Poll Results: do u have any query? | |||
| y:yes | | 5 | 100.00% |
| n:no | | 0 | 0% |
| Multiple Choice Poll. Voters: 5. You may not vote on this poll | |||
![]() |
fgets is always safe... cause in fgets we can specify the size of the string that should be read... in such a case we can be sure only the specified no of bytes will be read...
gets is not like that... it will read whatever we give and may overwrite the memory locations not allocated for that particular string variable...
eg:
For the first one using fgets, even if we give any string greater than 20 in length, it will accept only 20.... but in gets if we give string of length 30, it will accept all the 30 and over write the memory locations not allocated for acName...
Hope it clears your doubt...
gets is not like that... it will read whatever we give and may overwrite the memory locations not allocated for that particular string variable...
eg:
C Syntax (Toggle Plain Text)
char acName[20]; /* Using fgets */ fgets(acName, 20, stdin); /* Using gets */ gets(acName);
For the first one using fgets, even if we give any string greater than 20 in length, it will accept only 20.... but in gets if we give string of length 30, it will accept all the 30 and over write the memory locations not allocated for acName...
Hope it clears your doubt...
regards,
Ahamed.
Ahamed.
•
•
•
•
Hi gunjan,
Can you please tell me what is the difference between
void function(int*d);
and
void function(int &d);
both above are function declarations and both we do the changes to the original variable passed to the function. Then what is the exact difference.
Thanks in advance
Second one is "passing arguments as references".
You cannot do that in C, C always passes arguments by value (yes, even if you use pointers, but then it passes pointer as value, not original value pointed by pointer
)So, the first one is ok in C and C++
Second one is only C++
•
•
•
•
im having lot of problems in c and c++ programs...can u please tell me the sites where i ciuld find the solutions of almost all c/c++ programs..
![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C Forum
- Previous Thread: Game Of Life 3D
- Next Thread: Help Me Please
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





