User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 403,503 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,252 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 C advertiser: Programming Forums
Views: 6197 | Replies: 50
Closed Thread
Join Date: Aug 2006
Posts: 24
Reputation: amano is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
amano amano is offline Offline
Newbie Poster

Re: C programming - need some help

  #41  
Sep 1st, 2006
Originally Posted by andor View Post
Damn mistake again. Theoretical ican overflow so list func must be modified
void List()
{
   Contactbook = fopen("Contactbook.txt","r");
 
   if(Contactbook != NULL)
   {
      int i = 0;
      system("clear"); 
      printf("Current Entries: \n");
      while(fgets(contactbook.names, sizeof(contactbook.names), Contactbook) != NULL)
      {
         if (i % 5 == 0)
         {
            printf("%s", contactbook.names);
            i = 0;
         }
         i++;
 
      }
 
 
      printf("End of File \n");
      system("pause");
      fclose(Contactbook);
   }
   else
   {
      printf("Contactbook.txt open FAIL!\n");
   }
}


Oh now i get it. Although have passed it up, nevermind learning is a long life process.....

one more thing, i made my edit function like this ( using delete function and then add a new value into contactbook because i don't know how to overwrite the initial value containing in the previous file) Is it we have to use fseek. but how should we know the place in the array.

and you're right with white space thing. Is it we have to replace it with fgets? but if there's too many argument, how to write it. Just want to learn more.
 
Join Date: Jun 2005
Location: Novi Sad, Serbia
Posts: 273
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Rep Power: 6
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: C programming - need some help

  #42  
Sep 13th, 2006
<<several intervening off-topic posts were deleted>>
Originally Posted by WolfPack View Post
I marked it as solved. Since it is a relatively new thread, I don't see a need to close it.

Well the thread is not solved. Read post no 41
Originally Posted by amano
one more thing, i made my edit function like this ( using delete function and then add a new value into contactbook because i don't know how to overwrite the initial value containing in the previous file) Is it we have to use fseek. but how should we know the place in the array.

and you're right with white space thing. Is it we have to replace it with fgets? but if there's too many argument, how to write it. Just want to learn more.

>Is it we have to replace it with fgets?
In your case it's better to do it with fgets
>but if there's too many argument, how to write it. Just want to learn more.
Think. Now you have enough time to think some kind of solution. Search can be similar to list func but you need to change the logic of search func. If you still have a problem then post it.
Last edited by Dave Sinkula : Sep 13th, 2006 at 7:15 pm.
If you want to win, you must not loose (Alan Ford)
 
Join Date: Nov 2005
Location: Canada
Posts: 236
Reputation: dwks will become famous soon enough dwks will become famous soon enough 
Rep Power: 4
Solved Threads: 20
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: C programming - need some help

  #43  
Sep 14th, 2006
fflush dosn't work for input streams and I think it's system("cls"); instead of system("clear");

system("cls") for windows
system("clear") for unix(knoppix)

the problem right now that i want to cocentrate at is Search function and Delete function. Anybody know. Pls help me. Urgent.......
As andor mentioned:
Why not to use fflush(stdin): FAQ > Explanations of... > Why fflush(stdin) is wrong
What to use instead: FAQ > How do I... (Level 2) > Flush the input buffer

How to clear the screen: FAQ > How do I... (Level 1) > Clear the screen?

In case you ever intend to compile that program as C++, you can't call main() in a C++ program.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
 
Join Date: May 2006
Posts: 2,700
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 14
Solved Threads: 220
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: C programming - need some help

  #44  
Sep 15th, 2006
Originally Posted by dwks View Post
In case you ever intend to compile that program as C++, you can't call main() in a C++ program.


And you should never call main() in C either.
Age is unimportant -- except in cheese
 
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Rep Power: 4
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: C programming - need some help

  #45  
Sep 15th, 2006
Originally Posted by WaltP View Post
And you should never call main() in C either.

But standard doesn't stops anyone.
The key to eliminating bugs from your code is learning from your mistakes.
 
Join Date: May 2006
Posts: 2,700
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 14
Solved Threads: 220
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: C programming - need some help

  #46  
Sep 15th, 2006
Originally Posted by Grunt View Post
But standard doesn't stops anyone.

Standard also has gets() and goto, too. And when you're driving, the brake doesn't have to be used at a red light.

Bad practices are bad practices, even when they are allowed. The C standard also allows this program to compile and run:
#include <stdio.h>
int GetDenom(int val,int *den){int i;int dp=0;for(i=1;i<=(val/2);i++){if((val%i)==0){den[dp++]=i;}}den[dp++]=val;return(dp);}
int main(){int i, v;int val,den[100],denp;v=0;for(val=2;val<10000;val++){denp=GetDenom(val,den);if(v<denp)v=denp;printf("%4d",val);printf("(%3d):",denp);for(i=0;i<denp;i++)printf("%3d",den[i]);printf("\n");}printf("v=%d\n",v);return 0;}
Age is unimportant -- except in cheese
 
Join Date: Jun 2006
Location: India
Posts: 6,816
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: C programming - need some help

  #47  
Sep 15th, 2006
Yes i completely agree with Mr. WaltP, since old habits die hard. For small exercies it doesnt make a difference, but in the long run it causes a lot of problems. Correct methodology coupled with technical accuracy can only be achieved only if you try for it and want to learn new each day.
Otherwise its the same thing like many people who learn such things the hard way. (eg. building a 3d Game using an external engine).

Hope it helped, bye.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
 
Join Date: May 2006
Posts: 2,700
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 14
Solved Threads: 220
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: C programming - need some help

  #48  
Sep 15th, 2006
Originally Posted by ~s.o.s~ View Post
Yes i completely agree with Mr. WaltP

Mr.? Makes me feel old....

Originally Posted by ~s.o.s~ View Post
For small exercies it doesnt make a difference...

I really wish people would stop saying crap like this. It does make a difference whether large or small. It's just wrong. Period.
Age is unimportant -- except in cheese
 
Join Date: Jun 2006
Location: India
Posts: 6,816
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: C programming - need some help

  #49  
Sep 15th, 2006
Originally Posted by WaltP View Post
I really wish people would stop saying crap like this. It does make a difference whether large or small. It's just wrong. Period.


Err.. typing mistake maybe, what i wanted to say was:
"For small programming exercises it may not make a difference for you"...
and the you here is the one who thinks writing clumsy code doesnt make a difference but surely not me.

And by the way i am a proponent of methodological development and good design.

Hope it cleared away the misunderstanding.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
 
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Rep Power: 4
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Tutorial Re: C programming - need some help

  #50  
Sep 16th, 2006
Originally Posted by WaltP View Post
Standard also has gets() and goto, too. And when you're driving, the brake doesn't have to be used at a red light.

Bad practices are bad practices, even when they are allowed. The C standard also allows this program to compile and run:

I was simply highlighting that it's legal to call in C.
main( ) is just another function in C . Nothing special about it except the return type and parameter list. Though I am not encouraging anyone to call main( ) but you just can't say that it's a bad practise just like that without giving any reason.

There are lot of things like goto, void * etc whose use is discouraged by lot of people but there can be cases where they can come handy and be used. Even Stroustrup says that goto and void* can be useful in some cases. You can't just blindly say that these are bad practises. Basic problem is that people are ignorant and really don't know where and how to use them properly.
Last edited by Grunt : Sep 16th, 2006 at 12:55 am.
The key to eliminating bugs from your code is learning from your mistakes.
 
Closed Thread

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 12:31 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC