Dear All,

Many thanks for the answer of my first question though i had the answer for this from one who has already put this question forward.I have modified it and it has worked.Thanks!!
Now i want to optimize my coding by adding another condition so that it doesn't perform a loop unnecessary if the same data is passed everytimes.Can i cache a result somewhere in C!Should i use an if statement?
In fact i have 3 test cases in 1 module.But two of them have same data to be passed.so i want to cache an intermediate result whenever the same data is used.

Many thanks

Nalini

Recommended Answers

All 5 Replies

>Can i cache a result somewhere in C!
Yes, you can do just about anything in C.

>Should i use an if statement?
I'm sure you would need one somewhere. :icon_rolleyes:

>so i want to cache an intermediate result whenever the same data is used.
So what's the problem?

Hello

I dont know how to cache the result that's why i am asking.And about the if statement i have tried to add one but am getting error while compiling.

Grateful if you could help

thanks

Nalini

>I dont know how to cache the result that's why i am asking.
Caching is just saving data in memory for later use. It could be as simple as this:

int x;
int oldx;
int result;

...

if ( x != oldx ) {
  /* Don't bypass the calculation */
  result = ...
}

oldx = x;

printf ( "Result = %d\n", result );

Dear Narue

many thanks for all ur positive answers!will try to mail u the coding if i happen to shorten it.But if i cant i will mail u the whole!!please do help me..i will make and add those statements..but do correct me !
you seems to be really a guru in C!i have gone thru ur tutorials in C.thanks again

thanking you

Nal

Dear Narue

i am mailing u the coding but its ok if u cant go over it as i know its very long!:( i have removed the steps that need nt be optimised .But have pointed out whre the conditions need to be placed as i dont know hw to put it.It makes heavy use of pointers which i am learning slowly.I have 2 more to see by myself but this one seems to be the most difficult.

Just hope u can help me partly at least or explain to me hw this can be done.
thanks

Best regards

Nal

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.