csurfer 422 Posting Pro

@wildgoose

You're entering pounds calling it dollars.

Pound as a unit of weight not as a monetary unit.

@MrNoob

1>toupper() is defined in <ctype.h> and I don't see it in your headers.

2>
Even though the problems mentioned in above posts are right most of them are problems due to logical thinking "Tier" "Shipping cost" and all.Ya you calling artichokes for everything is a fault,but both of you failed to notice one major problem.

switch(scanf("%d",&groc))

Scanf returns the number of inputs it has successfully read not their value so if you feed in even 3 or 2 it has successfully read one input so it returns 1. So here you are not deciding the switch upon the choice of the user at all.Because on every successful read scanf returns 1 and the user is forcibly directed to choice 1 even if he chooses 3.
It should be as :

for(;;) //Your for statement only
{
     // The stuff you have written before switch
     scanf("%d",&groc);
     switch(groc)
    {
          //Switch conditions
    }
    //Other stuff
}

You both need to concentrate on what stuff you are dealing with.This is C language and it requires some patience and some effort.

csurfer 422 Posting Pro

sorry abt two threads. I didnt see in the forum my first thread. So i had to write another thread. Now its here

Mark one as solved so that people can direct their attention towards others in need.

csurfer 422 Posting Pro

Not only the errors mentioned in the post above it also has syntax errors and other major errors too.

1>

if(fp_in = NULL)

you are not assigning the pointer you need to check so its

if(fp_in == NULL)

Same goes for fp_out

2>Why are you exactly using exit .When you are using it at least call the function properly with a return value.

3>This is a C++ forum and this post is first of all not C++ its C. The only C++ thing I see here is the header <iostream> wonder why you even cared to use it.???:?:

4>Your starting line itself is hilarious

int main(int nNumberofArgs, char*psz[])

Where are you even using the command line parameters ???

The main thing wrong with your code is "You don't know which language you are writing it in...!!!".So try to put in some more hard work.you definitely can improve.

csurfer 422 Posting Pro

The node containing garbage value appears at the last..

So if your concern is just the last but one node that is if you say that the node whose node->link is your junk node and you don't want to read it then you can just do this :

for(p = L; p->next != NULL; p=p->next)

So that you stop writing just before the last node.

csurfer 422 Posting Pro

Its just a Compilers way of saying "The main object under my concern right now is this" ,as AncientDragon has stated its just a pointer which is maintained completely by compiler which the user cannot modify,but can make use of it foir referencing the current object.For more info try these 1 2.

csurfer 422 Posting Pro

Well I googled Dark GDK Tutorials in Google And I got just 10,600 links man,you too could have done the same well here is one I think would help you

csurfer 422 Posting Pro

Well my first thought to this thread was Reflex-i-on (reflection) and then I thought Soul Rockers.But ya the idea of Green extreme is good.

@OP : How didn't you come up with the name Green Extreme your login name sounds the same right ??? "Grn Xtrm"....;)

csurfer 422 Posting Pro

He hasn't just failed in coding the function AncientDragon he literally hasn't coded get get_record() ... ;)

And very bad coding style with the functions process_choice() and add_record() you are calling the functions but inserting the record literally whats the use man ??? Take the inputs from user and feed... If you want to do the same for 100 records according to your function you need to write in 100 records into program yourself. Thats bad.

You have just removed the essence of calling functions,the whole concept of modulation is gone here.

Ancient Dragon commented: Couldn't agree more :) +36
csurfer 422 Posting Pro
float computeAverage(int scores[], int count[])
{
    float average = 0;
    int sum = 0;
    for(int i = 0; i < MAX_SIZE; i++)
    sum += scores[i];
    average = sum / MAX_SIZE;

    return 0;
}

Your compute average function is still incomplete. 1st thing I don't see any usage of count[] that you pass to this function. 2nd You are computing the average but not even returning it ???
You have coded the initial read function well (I haven't checked the errors in it though if there are any ;)) Now just use the same concept and feed in the values to this array of yours and then compute the average thats it !!! :)

csurfer 422 Posting Pro

1>

if(initial=='^' ||initial=='/'||initial=='*'||initial=='+'||initial=='-')
{
while(!exp.empty() && exp.top()=='(')
{
temp2=exp.top();
x=opgreater(temp2,initial);

The actual statement needed here is exp.top()!='(' 2>And your code is just half way across.Its just extracting the symbols used.Its not converting it from input to output.

3>And ya no need to declare the function opgreater because you are defining the function before main and using it inside main.

csurfer 422 Posting Pro
main()
{
    int x,n, count=0;

           n=n+1
nxt:    cout<<"x=..";
          cin>>x;
     if(x>60)
          count=count+1;
     if(n==10)
          cout<<count;
     else 
          goto nxt;
}

You really sure that this is a code ??? Because I don't see any thing that this program can do... All I see is C++ being used. Not only you but any sensible person might find this program totally senseless...Its really hard even for us to know its LOGIC. Nothing is connected over here it is testing something which is never set and never even dealt with.Just loops around random number of times.

What did you really write this program for ???

csurfer 422 Posting Pro

You are not doing anything wrong, you just did not do anything accept for get it ready to be coded...

@u8sand : I really think you need to look at the code first and then give your comments.I found all the mistakes listed below.And you didn't find even one ??? Which compiler do you use by the way ? The one which corrects errors on its own ??? ;)

@GooeyG:

Lots of mistakes as such :

1>Where is Bstone class defined...???

2>

switch(Useroptions)

Where are you asking the user for options???

3>

default; //Default with a semicolon ???

4>Class member function defined within main ???

5>Enumeration within main ???

6>Name and Bdate that too integer ???

And many others...So correct them first.

csurfer 422 Posting Pro

You can do these :

1>Well if its just a matter of printing then "%.nf" where n is the number of digits after the "." you want to print in a floating point number.

2>If its really about conversion then you can know the IEEE floating point format for your machine and compiler architecture and then mask off the excessive bits by "logical anding" which ofcourse gets you into some troubles as you don't exactly know the number stored there and its stored in
<1bit-signbit><8bit-signed exponent><23bit-mantissa> for single precision 32 bit float format.

3>So may be you can do this :

* char num[10];
* sprintf(num,"%1f",<your actual float variable>);
* Now traverse through the array num[] and get the digits before "." the "." and digits after "." and then convert it into a number.

If there are any other ways even I would like to know. :)

csurfer 422 Posting Pro

Your usage is incorrect.You can use it as :

struct File1
{ 
//Your structure definition
};

struct FILE
{
//Your other members
struct File1 f1;//Here File1 acts as a abstract data type
};

You can also use the same thing above as this :

struct File1
{ 
//Your structure definition
}f1;

struct FILE
{
//Your other members
f1;//Here use f1 directly
};

For more details have a look at this.

csurfer 422 Posting Pro

You can use this in your function :

* Test if string is a character and then decimal value of that character (assumed to be a hex value A-F or a-f) can be done by : dec_value = 10+(int)((int)string[i]-65) (for upper case) or dec_value = 10+(int)((int)string[i]-97) (for lower case) .

With the above procedure you'll get the decimal value of your hex digit now you can go on with your computations without any problem right ??? :)

csurfer 422 Posting Pro

Well VC++,DevC++ and CODE::BLOCKS are great.And in case you don't like them you can always go back to good'ol Linux for g++.

csurfer 422 Posting Pro

Try the links in above post and ya try w3schools.com You have got lots of tutorials about everything related to web and you also can try out commands there only.It may be of some help :)

csurfer 422 Posting Pro

Hey you want us to do all the work ??? ;) Try on your own man...Put in some effort...Go on reading each line like a compiler does and ya if you are using Boreland C then may be F7 will help you trace program flow line by line.So try to debug it.

Some of the errors which you can easily find :

1>No semicolon after the struct cell.

2>You have declared A and L as LIST A,L; and LIST is itself struct node * type how can you pass pointer to this pointer...? As in p = *A; @adatapost :

Let him correct these primitive mistakes first adatapost memory allocation and other things are off limits if he cannot trace these simple mistakes.Basically he is not putting in the effort required!!!

csurfer 422 Posting Pro

We got what your question is but sorry to say you wont get any help here until you work on it first. Try coding it stage by stage.Let it be primitive itself don't worry.Code it and then come back to us for help.We will be very happy to help.

csurfer 422 Posting Pro

Ever heard of GOOGLE ??? You get loads there...!!!

jephthah commented: come on man. lighten up a bit. and "google.co.in" ? really? -2
csurfer 422 Posting Pro

thanks man.. it worked!:)
I need to use tc and borland c for now because its what we are using in school.

Forget what you are using in school.Those are outdated and useless. Get a good compiler like code blocks or devc++ or VC++ ok.If you work on these standard compilers then you can always work on less standard or totally crap compilers like TC which doesn't give you errors for most of the operations you do.

csurfer 422 Posting Pro

I hope your implementation of list is something like : typedef struct node * LIST; In the save_file function:

for(p = L; p != NULL; p=p->next)
fwrite(&p, sizeof(celltype), 1, fp);

You need to specify the address of the character array which holds the value.Say your structure is as

struct node{
char *store_this;
};

And after all the proper memory assignments for the node and the character array you should use it as:

for(p = L; p != NULL; p=p->next)
	fwrite(&(p->store_this), sizeof(celltype), 1, fp);

And the statements LIST *A and p=*A; are absolute nonsence because if p is of type node* then p=A is enough and if p is of type node then p=*A becomes meaningless.

And if you have implemented the list as something like:

typedef struct node LIST;

Then the statements p=p->link; loose value. Its kind of an confusion with your program.

csurfer 422 Posting Pro

Some major problems :

1>Get a standard compiler for yourself. They are all free of cost.Boreland C and Tc and all are not going to take you anywhere.

2>The load function works fine better use the second method I had suggested for "for loop" rather than the one implemented.Because the present condition loops one time extra.But still works.Some bug may creep in so the suggestion.

3>Problem is with your view function.You are calling it as view(s,n); .You cannot just pass any value for n you should keep a counter for total number of records in the file and that should be passed as n.Or atleast if you think that is users work to remember the number of records you atleast need to take the input for n before calling view as:

printf("Input the number records you want to view / input the number of records in file that you remember :");
scanf("%d",&n);
view(r,n)

It should be mainly implemented this is the function looping infinitely.With arbitrary value for n it will loop any random number of times.So infinite loop.

csurfer 422 Posting Pro

Post in your code or else attach the file.

I told you earlier itself that was just to show you the implementation.Thats it you need to research the things and work out for yourself. We here at Daniweb just show you the way we don't give you every details :)

csurfer 422 Posting Pro

Error: Put it in CODE TAGS. !!!

You have lots of errors in this code man...

1> In getData functions you are returning values return 0; at several places but its a no return void type of function. So either change the return statements or change the type of return for this function to int.

2>Every place with:

for(int j = 1; ........; ......)

Needs correction.This is C we are talking about here and it supports only :

int j;
for(j = 1; j < MAXCOL; j++)
{
}

And ya don't redeclare the same things over again.

3>In function studentAvg() multiple declaration of float *rowAvg1[][MAXCOL], float *rowAvg2 [][MAXCOL] ,When you are passing the values to the function then why redeclare it again ???

4>function :

int printData (FILE* results, const int scores[MAXROW][MAXCOL])
{
// statements
fprintf (results, " %d\n", getData);
fprintf (results, "High Score %d", highGrade);where is high grade???
fprintf (results, "Low Score %d", lowGrade);
fprintf (results, "Average %5.2f", quizAvg);
fprintf (results, "Grade %5.2f", studentAvg);
return 0;
}

Where are the values of getData highGrade lowGrade and all??? these are not even function calls.

I stopped at this point itself because you are so dumb that you haven't compiled the code at all. We are here to help not compile your stuff and show you every mistake of yours.Put in some effort ok.Daniweb is not your online compilation and debugging unit!!!

csurfer 422 Posting Pro

Errors :

1> You cannot code like this.isdigit() is a function:

if isdigit(cResponse);

It should be

if(isdigit(cResponse));

2>Be sure of the portability of scanf_s 3>Your program has a lot of mistakes.

*

{
printf("\n\tThis program will determine if you are old enough to vote:\n");
printf("\n\tPlease enter your age; ");
scanf_s("%d, %c", &iResponse, &cResponse);	
}

Useless Braces.

*The semicolon after your problematic if statement.With that its as good as not including that if statement.

*isdigit() checks for a digit 0 1 2 3 4 5 6 7 8 9 not for a number.

And many others so check.

And ya mainly use code tags.Is that so difficult???

csurfer 422 Posting Pro

no way doesnt work by the way i am using devc++

Ok I thought you were using TC,well even for devcpp Instructions #1,#2,#4 Hold good.

Make the change in instruction #4 of my earlier post it will work. I tried and its working fine.(If you have a file by that name in that location ;)).

csurfer 422 Posting Pro

Ya lots of ideas :

1> You could make use of code tags which would have made this post better.Read this.Or just click # on right top corner.
2> You could stop using extinct files like <conio.h>

And ya mainly :
3>If you are using TC and doing something like this :

fopen ("f:\text.txt" , "r");

Then you will face problems.Yoiu cannot just access any part of the file system.Just as you wish.Well if you want to try place that text file of yours inside bin of TC and try as

fopen ("text.txt" , "r");

4>More over the "\t" in your file name can cause you a problem so try "\\t" just in order to remove the special meaning of "\" within quotes.

csurfer 422 Posting Pro

I sense a problem here in your load file function :

for(ctr = 0; fp == 0; ctr++)
            fread(&(r[ctr]), sizeof(studrec), 1, fp);

You can correct it as

size_t c;
for(ctr = 0; c != 0; ctr++)
	c=fread(&(r[ctr]), sizeof(studrec), 1, fp);

Above code will take one extra loop to find the end so better

size_t c;
for(ctr = 0;; ctr++)
{
	c = fread(&(r[ctr]), sizeof(studrec), 1, fp);
        if(!c) break;
}

There are far better ways,this is just the least modification of your code.:)

And sorry salem this is happening second time with me today when I begin writin there would be no post and when I post it there would be a reply already...and we cant delete any post made :(

Salem commented: Don't sweat it, sometimes I'm 3rd or 4th - it's all good :) +36
csurfer 422 Posting Pro

Know one thing : To assure that its a palindrome you need to check the whole string and get positive results.But to say its not a palindrome you just need one dissimilarity in your check. So you can just do this...

d=strlen(str)-1; 
for(i=0;i<=d;i++)
{
     if(str2[d-i]!=str[i])
    {
         flag=1;
         break;
    }
}
if(flag==0)
            printf("palindrome");
else
            printf("not palindrome");

Usage of extinct headers and functions clrscr() @ Ancient Dragon :

int x;
x = strlen(str) - 1;
for(i = 0; flag == 0 && i < d; i++, x--)
{
if( str != str[x] )
{
flag = 1;
}
}

That should be x not d ;).

csurfer 422 Posting Pro

Well it crashed when I tried it.Ya it does create a mem leak if not a crash.

Well we don't have a problem with new the problem is with delete.Read the answers again we have already mentioned the correction.You can check this link for better info.

csurfer 422 Posting Pro

Not probably a crash but it will definitely crash the second time.Because the first delete will deallocate the memory reference with respect to pArray then second time when we try to deallocate the memory references we try for pArray[0] to pArray[9] but parray[0] is already de allocated by first statement.
Just use the second statement thats enough.

How come you are posting a problem about new and delete in a C forum ??? Its C++ forum you should post it in.

csurfer 422 Posting Pro

oh!! that wa a typo.. yeah u assumed it rite , that was 'ptr' instead of B in the return statement.

yeah, i m not deleting it. so, i m going against the OOPs concept here.. when i am creating an object using 'new' operator and it shud be deleted using 'delete' operator explicitly. so if i never eve delete it , will it result into memory issue , specifically a segmentation fault.

thanks in advance.

Ya it will result in a memory issue but thats called a Memory Leak not a segmentation fault.Segmentation fault occurs when you access illegal memory(not assigned to your code).For example :

int array[10];
array[10]=10;//Segmentation fault because your limit is upto array[9]
csurfer 422 Posting Pro

@wildgoose :What you mentioned was one of the better ways to do the problem. I told the OP that it can be done even without that too just after sensing his difficulty in understanding basic concepts.And I didn't want to make his implementation more problematic(for him of course) by including another C concept(structures) here. :)

csurfer 422 Posting Pro

One of the problems I see is this

return *output;

It is actually returning output[0] here when you want it to return the address of output array.
It should just be

return output;

Sorry fellows Daniweb is loading too slow on my side so when I was posting I couldn't see your replies... ;)

Hiroshe commented: Thanks anyway ;-) +2
csurfer 422 Posting Pro

Why do you guys don't put in a bit of extra seconds to type what you need in google ???

#1 Your ascii table (it took me all of 2 seconds to get it)

#2 Wild goose has defined it in a very good way.

#3 You don't even need to use structures for this.You can do it directly.Simple implementation.Try it.Then post your errors here.

csurfer 422 Posting Pro

Well you can always write your own function and add it to the headers and include it in all your usages. Its quite common . If its too good then it may be included in the standard headers in future ;).

csurfer 422 Posting Pro

You are at the right place and you have hell lot of information available on web about CPP . Here are your books,time saving tips and practice problems. You had all these at the page start itself ;).

csurfer 422 Posting Pro

Well its like a puzzle, there are boxes , named like aa,ab,ac,ad,ae,ba, ....... ee

and values in those are like bc,ab, .... randomly shuffled

smallest or largest steps one should have to take for a given order

I know it would be better to do it without reflection,but just curious :)

Can u ppl suggest method for too,i am kinda stuck there

Be precise and specific in your definition of your problem and post the part which is giving you errors.In that way we can help you better.

csurfer 422 Posting Pro

This is actually what the debugger does more properly ... right???

csurfer 422 Posting Pro

@siddhant3s : Well what you have written is for predefined things,that is if a programmer knows that he is going to initialize variables by name x y z then he can maintain an array to know the values stored in those variable names. And its static. The compiler does it every day every time. May be not possible in C C++ but a lexer and parser combination can do it I suppose.And may be it can even be done in Assembly.Isn't it guys ???

csurfer 422 Posting Pro

Here you wont get any help until you show some effort... Most of us here are students,and we too learn the same way...so stop chikening out and try!!! You will do it.

csurfer 422 Posting Pro

Ya we are too good for such small programs...Now do it yourself smart fellow...!!!

csurfer 422 Posting Pro

Have a look at C SEQUENCE POINTS in google.You'll get to know a lot.

csurfer 422 Posting Pro

Woooosh......!!! Don't worry Sid you'll get the stuff you need...the OP will pay you with these for writing out her program ;) if she could get away from all our flaming !!! :)

csurfer 422 Posting Pro

@OP : If you had put in half of the effort what Vernon has put in the above post you would have solved your problem easily by now !!!

csurfer 422 Posting Pro

Wow such a nice problem to solve !!! I solved it now you too try !!! :)

csurfer 422 Posting Pro

You are not lost after coding this much you are lost from the beginning...

Hell lot of mistakes :

1> [#include <iostream> Typing mistake

2>

int 
int main(void)

What is this form ???

3> cout <<a1[45]<<endl; Segmentation fault illegal memory referenced alloted memory is from a1[0] to a1[44] for declaration int a1[45]; 4>

if (a2[50] % 5 ==0)
cout<<a2[50]<<endl;

Segmentation fault again

5> int max(0); What is this exactly???

6>

if (a1[45] > max)
max = a1[45];

Segmentation fault again.

And USE CODE TAGS and for finding minimum and maximum you can follow this algorithm

int min,max;
//Loop through a1[] first and initialize min=max=a1[0]; Now for every i ahead
if(a1[i]<min) min=a1[i];
if(a1[i]>max) max=a1[i];

//Now loop through a2[] ,for every i
if(a2[i]<min) min=a2[i];
if(a2[i]>max) max=a2[i];

//YOu'll have both min and max values for both arrays combined.
csurfer 422 Posting Pro

I referred not only the above links but also 7.11,7.17,6.3.2.3 etc of www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf before posting the above code. And I advocated for the standards defined and most of the posts say 0 was bought in later and may be problematic in some situations,so you need to know when to use 0 and when you are compelled to use (void*)0 zero specifically.So its at least better to know how NULL is actually defined.

tux4life commented: Nice link to the standard :) +10
csurfer 422 Posting Pro

@adatapost : There is a huge difference between just 0 and NULL . You may not get an error but that doesn't mean you are right. ASCII 0 is null character value even using '\0' is better when using null character rather than just a 0 and even in that condition too the compiler doesn't give an error but this is better.

But using 0 for NULL (null pointer) is inviting trouble at some point.NULL (null pointer) is defined in a standard way as (void *)0.So...

null character proper usage '\0'
null pointer correct usage NULL or (void *) 0

rather than just a 0 for both.

Even though just a 0 is correct instead of NULL when used with pointers its better to maintain the distinction between integer 0,null character,null pointer and finally ASCII value 0