Shankye 36 Junior Poster

Yup ...

if (file = fopen(file_name, "r"))
{
       printf("Exists");
       fclose(file);
}

Merry Christmas to u too ...

Shankye 36 Junior Poster

Apache 2.2.11
PHP 5.3.0
MySQL 5.1.36

http://www.wampserver.com/en/download.php

Shankye 36 Junior Poster

Its ok friend ..

Hope your problem solved now ..

Shankye 36 Junior Poster

Problem with exit()

exit(0);

Use { } may take few seconds more to type but they help

Check this now

#include<stdio.h>
main()
{
int a,b,c,sum=0,i;
printf("enter the numbers");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
for(i=sum;i<=sum ;i--)
{
        if(i==a || i==b || i==c)
        {
        printf("%d the greatest",i);
        exit(0);
        }
}
}

looks so neat and easy to understand

Shankye 36 Junior Poster

Did you tried to compile it??

in First line only you have so many mistakes ..

sum = o

It showed be

sum = 0

remove ` after i..

Use { } correctly

and in

printf("%d blah blah");

what you are printing ????
i ?? sum ???

Make this changes compile it,
if got error copy paste that code..

Shankye 36 Junior Poster

enclose within CODE tag

Shankye 36 Junior Poster

WTFFFF,.. Green color not showing up in my comments.. X(

Shankye 36 Junior Poster

Toooooooooo Cool .. Super cool...

Mera
Bharath
Mahan

Shankye 36 Junior Poster

Toooooooooo Cool .. Super cool...

Mera
Bharath
Mahan

:) :) :) :)

Shankye 36 Junior Poster

@Sean
So sweet of you .. But this community is not being sweet to others..

I had voted down for posting FULL SOURCE CODE ..

Shankye 36 Junior Poster

@Sean
Its C thread ..

Shankye 36 Junior Poster

Thank you :)

If problem solved mark this thread solved ..

Happy programming :)

Shankye 36 Junior Poster

@Jason

conio.h it is not part of the C standard library,

clrscr also not standard function ..

And he not doing any magic, just giving his work to system..

Shankye 36 Junior Poster

You want to show how to shutdown ??????????????????????

Shankye 36 Junior Poster

Experts are toooo busy to read full thread ..

Oh i didnt knew thr is scanf function :D

He said he couldnt use it and wanted some other way ..

vedro-compota commented: you are right)))))))))) +1
Shankye 36 Junior Poster

@Trentacle
He casting to int directly dude how he will get correct int value??


@Vedro

You can do like this, (with some Portability issues ;) )

n = getchar()-'0';

Something good will come out ;) :D

Shankye 36 Junior Poster

Oopss no idea

may be consider one poly use two loops Check term by term with all remaining poly

considering p4 (in program p[0])

for(i=0; i<MAX_EXP; i++)
{
 for(j=0; j<k; j++)
 {
   for(int m=0; m<k; k++)
    {
     if(p[0].term[j].expo = p[i].term[m].expo)
        p[0].term[j].coeff += p[i].term[m].coeff;
    }
  }
}

But if exponent are in decreasing order and dont think this type of comparisn may be needed ..

Hope it helped

Shankye 36 Junior Poster

ok thanks

How about going 4 5 years back in schooling time and doing how we used to do in school

p1 = 3x^2 + 2x^1 + x^0
p2 = 1x^2 + 1x^1 + 2x^0
----------------
multiplying term by term

p4 = 0x^4 + 0x^3 + 6x^2 + 4x^1 + 2x^0
p5 = 0x^4 + 3x^3 + 2x^2 + 1x^1 + 0x^0
p6 = 3x^4 + 2x^3 + 1x^2 + 0x^1 + 0x^0
-------------------------------------

Adding above will give our answer ..


I think this approach will be easier ..

mul(poly p1, poly p2, poly *p3)
{
poly p[p1.noOfterms];

	for(int i=0; i<p1.noOfTerms; i++)
	{
	   for(int j=0,int k=0; j<p2.noOfTerms; j++,k++)
            {
		p[i].terms[k].coeff = p1.terms[i].coeff * p2.terms[j].coeff;
	        p[i].terms[k].expo  = p1.terms[i].expo  + p2.terms[j].expo;
	    }
	}

   // Comapare exponent and if equal add their coeff
}
Shankye 36 Junior Poster

ok thanks :)

How about going 4 5 years back in schooling time and doing how we used to do in school

p1 = 3x^2 + 2x^1 + x^0
p2 = 1x^2 + 1x^1 + 2x^0
----------------
multiplying term by term

p4 = 6x^2 + 4x^1 + 2x^0
p5 = 3x^3 + 2x^2 + 1x^1
p6 = 3x^4 + 2x^3 + 1x^2
-------------------------------------

Adding above will give our answer ..


I think this approach will be easier ..

mul(poly p1, poly p2, poly *p3)
{
poly p[p1.noOfterms];

	for(int i=0; i<p1.noOfTerms; i++)
	{
	   for(int j=0,int k=0; j<p2.noOfTerms; j++,k++)
            {
		p[i].terms[k].coeff = p1.terms[i].coeff * p2.terms[j].coeff;
	        p[i].terms[k].expo  = p1.terms[i].expo  + p2.terms[j].expo;
	    }
	}

   // Using a loop Comapare exponent and if equal add their coeff

}
vinitmittal2008 commented: Like ur suggestion :) +1
Shankye 36 Junior Poster

B4 posting it want to say im student and if any mistake im sorry

May be like manually how we do ...
Assign first term of p4 to p5 and then go on checking if same exponent term exists,
If exists add thr coefficinents
and if not than add that term to p5, it will be p5.term[1]
and again go on checking again if same exponent in p4 exists if not add next term and so on ..

May be like

poly p5;

p5.term[0] = p4->term[0];
p5.noOfTerms = 1;

while( i <= k)
{
    for(i=0; i <= p5.noOfTerms; i++)
     {
        if(p5.term[i].expo == p4->term[i]->expo)
            p5.term[i].coeff += p4->term[i]->coeff ;
     }
   /* If same exponent term in p5 and p4 not found
      add that term to p5 
      and p5.noOfTerms++ */
}
Shankye 36 Junior Poster

And if problem solved close this thread ..

Shankye 36 Junior Poster

oh thts nice..
strcmp is better way stick with this but i think u need correcting on 4th line..
U scannig string so use %s and dont use address operator(&

If its working its fine :)

Shankye 36 Junior Poster

I not getting what help you expecting from all??????

see your code

while(1)
		{
		printf("\ntype 'ls' to see your whats in your current directory or press x to continue ");
		scanf("%c", &input);
		if(input[0] == "ls")
		{
		system(input);
		continue;
		}
		else
		{
		if (input[0] != "ls")
		break;
		
		
	}

You scanning single char with %c and thn taking suggestion to use strcmp??

Dude first tell what is input???????
<b>char???
Array of char???
pointer????</b>

what is tht??

Shankye 36 Junior Poster

Write to fflush all the buffers and make stdin and stdout clean..

IF possible post full code, will try to compile and check whether it works here

Shankye 36 Junior Poster

getch() completely worked fine for me ..

Here is code which compiled and worked for me ..

#include <stdio.h>

int main (void)
{

  char temp;
  while(1)
  {
     if( (temp=getch()) == 'x')
     {
        printf("Bye");
        exit(0);
     }
     printf("Looping");
   }
 return(0);
}
Shankye 36 Junior Poster

May be getc() wont return unless enter hit so use getch() which returns key pressed and neither echo it to the screen..

if   ((answer = getch()) == 'x')
Shankye 36 Junior Poster

First of all, when you scanning float u should use %f

scanf("%f", &num);

I think u need an int operand to to use with %..
so cast the float to int with (int)

rightdigit = (int)num % 10;
Shankye 36 Junior Poster

Welcome ..
Mark it solved ..

Shankye 36 Junior Poster

I run your program, didnt got any error ..

On 16th line while opening file you gave extra space between C: and \\

c: \\familyin.txt"

i just removed that space and program worked fine..

Shankye 36 Junior Poster

@Dragon I think he is opening two different files ..

One is familyin.txt and familyout.txt..
Whr you talking about those two???

Ancient Dragon commented: Yes, you are right :) +34
Shankye 36 Junior Poster

Multiples of 3 gives 27

the remainder of the operation is given by modulus operator(%)

so
.
27%4 = 3 which is remainder obtained by division ..

Shankye 36 Junior Poster

Narue posted just b4 me .. U scan lk tht and later remove the first char (,) or else you can scan a single char and discard that char ..

Shankye 36 Junior Poster

String ends at space so it wont scan countinued name after space..

fscanf(pt,"%d %[^,]s ",&num,surname);
        fgetc(pt);
        fscanf(pt,"%[^\n]s",name);
Shankye 36 Junior Poster

pointer is not initialized ..
Following code ay help ..

#define MAX 100

data first;
data *fp;

first.name = malloc(MAX);

fp = &first;

scanf("%s",first.name);
printf("fp is %s\n",fp->name);
Shankye 36 Junior Poster

U can add current directory to $PATH
PATH=$PATH:.

Shankye 36 Junior Poster

Program works fine with scanf also but fflush(stdin) at 19 n 22 are must ..