vinitmittal2008 37 Junior Poster

where is ur program code???

vinitmittal2008 37 Junior Poster

I also dint know that..... Thanks Narue.

vinitmittal2008 37 Junior Poster

Embed your program between code tags..

vinitmittal2008 37 Junior Poster

@Joey_Brown

just want to understand your question...
what would be the output of your program if input is this??

Input

a b c
d e b
c b a
d f c

output
??

vinitmittal2008 37 Junior Poster

it's C Forume buddy.. Either post your program in C code or move it to c++ Forume.. :)

vinitmittal2008 37 Junior Poster

Exactly what are you trying to do???

vinitmittal2008 37 Junior Poster

Make your program as Adak says...:)

vinitmittal2008 37 Junior Poster

if you just want to use file name without space then use this

FILE *fp;
char filename[40];  // you can use max lenght 260

strcpy(filename,"c:/");

printf("\n Enter File Name:");

scanf("%s",&filename[3]);

fp=fopen(filename,"a+");
vinitmittal2008 37 Junior Poster
int main(){
	struct people{
    
		char name[20];
		short age;

	} people;

struct people me;



printf("\n Write your name:");

fgets(me.name,20,stdin);

printf("\nHow old are you:");

scanf("%d",&me.age);

return 0;
}
vinitmittal2008 37 Junior Poster

ok now try this save your text.txt file (which you are trying to open in read mode)at a perticular location like at C or D drive and specify that location in fopen like this...

pFile = fopen("D:\\text.txt", "r")

and check whether it opens or not.

vinitmittal2008 37 Junior Poster

line 27 why are you using fclose here..

vinitmittal2008 37 Junior Poster

hey which file you are trying to open..

vinitmittal2008 37 Junior Poster

does'nt seems any problem with this code. please post your complete code here..

vinitmittal2008 37 Junior Poster

your program is quite confusing (atleast for me), but at line 64..
instead of

current->pPrev = current->pNext;

i think it should be

current->pPrev->pNext = current->pNext;
vinitmittal2008 37 Junior Poster

I checked your output file.. its working friend.. just add a printf statement just after flag=1 statement as i edited in my above post.

you have already passes x[0]=3 thats why its not taking same value in x[1], just add this

flag=1;
printf("\n Number Already Exist!,Enter Another Value\n"); // add this 
break;
vinitmittal2008 37 Junior Poster

i watch your output my dear friend.. i think its working.
you have already passed x[0]=3, that is why its not taking same 3 value in x[1], pass different value in x[1] and it will definetely prompt for x[2] and so on...

vinitmittal2008 37 Junior Poster

please post your latest code after making above change..

vinitmittal2008 37 Junior Poster

declare a int variable flag and you can try something like below code

for (ctr=0;ctr<as;ctr++)
{
  do{
   printf ("\nx[%d]= ", ctr);
   scanf ("%d", &x[ctr]);
   if(ctr>0)
   {
     for(j=0;j<ctr;j++)
     {
       if(x[j]==x[ctr])
        {
          flag=1;
          printf("\n Number Already Exist!,Enter Another Value\n");
          break;
        }
       else flag=0; 
     } 

   }
   else flag=0;
 }while(flag==1);
}
vinitmittal2008 37 Junior Poster

okkk... wait for a minute...

vinitmittal2008 37 Junior Poster

>> where it should prompt the user to enter another value for x if the value corresponds to either the values of other elements.

for (ctr=0;ctr<as;ctr++)
{

printf ("\nx[%d]= ", ctr);
scanf ("%d", &x[ctr]);
// here that condition should be checked
}
vinitmittal2008 37 Junior Poster

could you please tell me which sorting algorithm you are using in your program..

vinitmittal2008 37 Junior Poster

@darkbreaker

i thing you forgot

average = (float)sum / ARRSIZE;
vinitmittal2008 37 Junior Poster
#include <stdio.h>
#include <process.h>

int main (void)
{
FILE *pFile;
char ch;


// open the file

if((pFile = fopen("text.txt", "r"))==NULL)
 {
   printf("\n Error: Can't open File \n"); 
   exit(0);
 }
 \\ Reading from file and displaying on screen..

 while((ch=fgetc(pFile))!=EOF)
     putchar(ch);

 fclose (pFile);

 return 0;
}
vinitmittal2008 37 Junior Poster

i think you program is just read data from the file and display the output on the screen, if its that simple then no need to use "char name [9999]" which is occupying 9999 bytes of memory. this could be done by just reading char by char from the file..

vinitmittal2008 37 Junior Poster

First make sure do you have that perticular file on specified location which you are trying to open in read mode...

vinitmittal2008 37 Junior Poster

Hii Kalpana,

plese post your program code(whatever effort you have done) here, we'll surely help you.:)

vinitmittal2008 37 Junior Poster
scanf("%d", &week);

The vast majority of functions will give us some indication of success or failure.
Especially with input it's best to make sure that the call succeeded before
proceeding as if it did. In the case of scanf,
a successful call will return the number of items converted:

if (scanf("%d",&week) == 1) {
  /* Success */
}
else {
  /* Failure */
}
vinitmittal2008 37 Junior Poster

okk... try this code, i made little change to your code..

#include <stdio.h>
#include <ctype.h>
int main()
{
	char SubCode[30];
	int week, student;

	printf("What Is The Course Code? ");
	scanf("%s", SubCode);
	fflush(stdin);

	printf("How Many of The Total Weeks? ");

	while(scanf("%d", &week)!=1)
	{
		fflush(stdin);
		printf("You Have Enter Out of Range\n");
		printf("Please Re-enter Again\n");
		printf("How Many of The Total Weeks? ");

	}

	printf("How Many Students In This Class? ");

	while(scanf("%d", &student)!=1)
	{
		fflush(stdin);
		printf("You Have Enter Out of Range\n");
		printf("Please Re-enter Again\n");
		printf("How Many Students In This Class? ");
	}
  return 0;
 }
vinitmittal2008 37 Junior Poster

well.. i don't think there is anything left to comment but there is so many things to learn (specially for me) from the above post.. :)

vinitmittal2008 37 Junior Poster

ohh, i catch it wrong..

vinitmittal2008 37 Junior Poster

>>I'm just unsure how to return the values from the structure with designating a matrix like this:

int matrixGetElement (Matrix* m, int r, int c) //that is without having the "m"
{
	
}

Sorry! could'nt get the problem.

vinitmittal2008 37 Junior Poster

" i just create 1 exe file so that when i double click it. it automatically runs & produces the required output.although the s/w itself produces the exe file. but it opens along with all the supported/assosciated files with it. i just require only 1 exe file. "

i think kapil wanted to say when he is running that created exe file thats running well but its also opening the source code of that exe file.
he just want to keep that exe file in seprate folder and when he or someone else click on that exe file only that exe file get executed.

vinitmittal2008 37 Junior Poster

Try this one also..

# include <stdio.h>

int main(){
    int a=10,b=3,reminder;
    // suppose you want a%b.

     reminder = a -(a/b)*b;
     
     printf("\n\n  Reminder of %d/%d is %d",a,b,reminder);
     return 0;
   }

This will also work like % operator..

Ancient Dragon commented: nice -- a lot better than mine :) +34
Snehamathur commented: Appriciated +1
vinitmittal2008 37 Junior Poster

In the loop i+j requires the addition of i and j in order to resolve the index into pWord. That takes unnecessary clock cycles. Just simply continue to use the i counter that already contains the value that is needed in the loop.

Thanks for clearing me!!

vinitmittal2008 37 Junior Poster

Or to avoid costly addition operations

for (j = 0; pTemp[j] != '\0'; j++,i++)
      pWord[i] = pTemp[j];
   pWord[i] = '\0';

@ Ancient Dragon
Sir, please clear "to avoid costly addition operations"....

I am regularly following your posts and its helping me alot to improve my knowledge.:)

vinitmittal2008 37 Junior Poster
//Function Protoype
char* stringCat(char *pWord, char *pTemp);

//Function call in main
 stringCat(stringCat(word, ": "), temp);
   printf("\n\nConcatenation: \"%s\".", word);
   printf("\n\n");

//Actual Function
char* stringCat(char *pWord, char *pTemp)
{ 
   int i;   
   int j;
   
   for (i = 0; pWord[i] != '\0'; i++);    // Notice the ;
   for (j = 0; pTemp[j] != '\0'; j++)
      pWord[i+j] = pTemp[j];
   pWord[i+j] = '\0';
   
   return pWord;
}
vinitmittal2008 37 Junior Poster

main()
{
int k=35;
printf("\n %d %d %d",k==35,k=50,k>40);
}


for above code y d o/p is: 0 50 0 ?
i mean it must b 1,50,0 as d first comparison is true

please start new thread for this question.. don't ask your question in someone else thread.. :)

vinitmittal2008 37 Junior Poster

Try this program:

# include <stdio.h>

int main()
  {
   int i,flag=0;
   int num[10];
   printf("\n\n\t\t Enter 10 values:");
   for(i=0;i<10;i++)
     scanf("%d",&num[i]);

   for(i=0;i<9;i++)
    {
       if(num[i]<num[i+1])
	  flag++;
       else if(num[i]>num[i+1])
	  flag--;
    }

   if(flag == -9)
      printf("\n\n  decreasing..");
   else if(flag == 9)
      printf("\n\n  increasing..");
   else if(flag == 0)
      printf("\n\n  equals");
   else
      printf("\n\n Disorderly");


   return 0;
}
vinitmittal2008 37 Junior Poster

Its easier to make such program using If-else, the logic could be quite simple.. think a bit...

vinitmittal2008 37 Junior Poster

@gahhon

ya, your program is behaving so weird its because when we are pressing any alpthabet from keyboard its taking a garbage value..

int isalpha(int c);

The c argument is an int, the value of which the application shall ensure is representable as an unsigned char(0-255) or equal to the value of the macro EOF. If the argument has any other value, the behavior is undefined.

vinitmittal2008 37 Junior Poster

Its Working properly on my PC..

vinitmittal2008 37 Junior Poster

Hey becka221,

Now your problem has been solved so mark this thread as solved...

vinitmittal2008 37 Junior Poster

If Above is your question then the code could be...

#include <stdlib.h>
#include <stdio.h>

int main ()

{
    int Tab[5][3], i, j, GrandA = 0, GrandB = 0, GrandC = 0;
    int index_a=0,index_b=0,index_c=0,big_a,big_b,big_c;

    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 5; j++)
        {
            scanf("%d", &Tab[j][i]);
        }
    }

    printf("\n\n");

    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 5; j++)
        {
            printf("%d\t", Tab[j][i]);
        }
        printf("\n");
    }

    for(i = 0; i < 3; i++)
    {
        printf("\n");
        big_a = 0;
        big_b = 0;
        big_c = 0;
        
        for(j = 0; j < 5; j++)
        {
            if(big_a < Tab[j][0])
            {
                big_a = Tab[j][0];
                index_a=j;
            }

            if(big_b < Tab[j][1])
            {
                big_b = Tab[j][1];
                index_b=j;
                
            }
            if(big_c < Tab[j][2])
            {
                big_c = Tab[j][2];
                index_c=j;
            }
         }
        GrandA +=big_a;
        GrandB +=big_b;
        GrandC +=big_c;
        Tab[index_a][0]=Tab[index_b][1]=Tab[index_c][2]=0;
   
    }
    printf("%d ", GrandA);
    printf("%d ", GrandB);
    printf("%d ", GrandC);

 return 0; 
}

If its not your question then please describe it with example...

vinitmittal2008 37 Junior Poster

Ohh.. I also misunderstood your question.. please ignore my above post....

you want to sum of 3 highest numbers of line1 in GrandA ... and so on.....

line1: 1 3 4 5 6 GrandA= 6+5+4

line2: 5 6 7 8 3 GrandB= 8+7+6

line3: 5 4 4 3 2 GrandC= 5+4+4

I think that's your question...

vinitmittal2008 37 Junior Poster

How much i could understand, i think you are trying to do this..

#include <stdlib.h>
#include <stdio.h>

int main ()

{
    int Tab[5][3]={0}, i, j, GrandA = 0, GrandB = 0, GrandC = 0,Sum;

    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 5; j++)
        {
            scanf("%d", &Tab[j][i]);
        }
    }

    for(i = 0; i < 3; i++)
    {
        for(j = 0; j < 5; j++)
        {
            printf("%d\t", Tab[j][i]);
        }
        printf("\n");
    }

   for(j = 0; j < 5; j++)
     {
      if(GrandA < Tab[j][0])
           GrandA = Tab[j][0];
      if(GrandB < Tab[j][1])
           GrandB = Tab[j][1];
      if(GrandC < Tab[j][2])
           GrandC = Tab[j][2];
     }
    Sum=GrandA+GrandB+GrandC;
    printf("%d ", GrandA);
    printf("%d ", GrandB);
    printf("%d ", GrandC);
    printf("\n %d",Sum);
    
  return 0;
  
 }
vinitmittal2008 37 Junior Poster

try this

#include<stdio.h>
#include<conio.h> //avoid using conio.h


int main()
{
char gender;
char location;
char health;
int age;


printf("enter ur gender F: Female M:Male");
gender=getchar();

printf("\n Enter ur age");
scanf("%d", &age);

fflush(stdin);
printf("Enter your location E for city F for village ");
location=getchar();
fflush(stdin);
printf("\n Enter Health C for Excellent D for Poor");
health=getchar();



if(gender=='M' && health=='C' && location=='A' && (age>=25 &&age<=35))
{
printf("\n Allowed to insure");
printf("\n Premium rate will be 4 per thousand");
printf("\n Max amount can be 2lacs");
}

else if(gender=='F' && health=='C' && location=='A' && (age>=25 &&age<=35))
{
printf("\n Allowed to insure");
printf("\n Premium rate will be 3 per thousand");
printf("\n Max amount can be 1lacs");
}

else if(gender=='M' && health=='D' && location=='B' && (age>=25 &&age<=35))
{
printf("\n Allowed to insure");
printf("\n Premium rate will be 6 per thousand");
printf("\n Max amount can be 10 Thousand");
}

else
{
printf("Not allowed to insure");
}

getch();
return 0;
}
vinitmittal2008 37 Junior Poster

scanf function always causes this type of problem.. specially when you are using it for char after using it for integer variable,

use getchar() function for inputting char variable...

vinitmittal2008 37 Junior Poster

Embed your program code between code tags...

vinitmittal2008 37 Junior Poster

Just learn the use of strcpy, strcat and itoa function.. and it would be quite easy to implement such code..:)

Have a Look..

# include <stdio.h>
# include <string.h>
# include <stdlib.h>
int main()
{
 char fname[12];
 char num[3]={"00"};
 int i;
 for(i=1;i<=20;i++)
  {
   strcpy(fname,"data-");
   if(i<10)
   itoa(i,&num[1],10);
   else
   itoa(i,num,10);
   strcat(fname,num);
   strcat(fname,".txt");
   puts(fname);

 }

 return 1;
}
vinitmittal2008 37 Junior Poster

Hi Vinit,

I hope your problems get solved.

Thanks
Perry

hey My Problem??

Its not my problem.!