vinitmittal2008 37 Junior Poster

well.. i could not understand the need of copystring function in your program.
you are using two pointer to char type of variables. when we deal with pointers then this could be done by = operator..

try this one.

#include <stdio.h>

int main(){

	char* string1="Hello World!!";
	char* string2;
	
	printf("string1: %s\n",string1);
	printf("Copying string1 to string2....\n");
	
	string2 = string1;
	
	printf("Now string2:%s\n",string2);
	
	return 0;
}

or if you just want your program to work then try this code

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

void copyString(char*,char**);
int length(char*);

int main(){

	char* string1="Hello world!!";
	char* string2;

	printf("string1: %s\n",string1);
	printf("Copying string1 to string2....\n");
        copyString(string1, &string2);

	printf("Now string2: %s\n", string2);
    
	return 0;
}

void copyString(char* string1, char** string2){
    char *temp  = (char*) malloc(sizeof(char) * length(string1));

	do{
		*temp = *string1;
		string1++;
		temp ++;

	}while( *string1 != '\0');
    *temp = '\0';
    *string2 = temp;
}

int length(char* string){

	int i;

	for(i=0;string[i]!='\0';i++);

	return i;
}
vinitmittal2008 37 Junior Poster
scanf("%d ",&a[ctr]);

Remove space after %d its causing problem

scanf("%d",&a[ctr]);
vinitmittal2008 37 Junior Poster

@ gaurav
I am also using CODEBLOCKS and i compiled your program and its working fine. its showing sorted output after inputting desired values..

vinitmittal2008 37 Junior Poster

Post your code that you have tried and not working.. and please start new thread for new problem.. after your problem get solved mark your thread as solved..

vinitmittal2008 37 Junior Poster

For that you need a good knowledge of programming, like you need to know worst case complexity, best case complexity and Average time complexity.
Read This

Snehamathur commented: Thanksss +1
vinitmittal2008 37 Junior Poster

Try this code..

# include <stdio.h>
# define MAX 100
int main(void)
{
    int oddcount, evencount;
    int array[MAX],i,n;

    printf("\n Enter Array Size (Between 1 to %d ): ",MAX);

    scanf("%d", &n); // User enters Array Size

    for(i = 0; i < n; i++)
    {
       printf("\n Enter %d value: ",i+1);
       scanf("%d", &array[i]); // Allows user to enter values into the Array
       }

    putchar('\n');
    printf("\nArray Values: ");
    for(i = 0; i < n; i++)
    {
       printf("\n [%d] value is %3d ", i+1, array[i]); //Prints out the array -- this is where program stops it should carry on down
    }
     //**************************************//
    oddcount = 0;
    evencount = 0;

     for (i = 0; i < n; i++) // Code determines wheter odd or even.

     {
          if (array[i] % 2 != 0)
          {
            //printf("\nThe number %d Is Odd.\n", i);
            oddcount ++;
          }

          else
          {
            //printf("\nThe number %d Is Even.\n",i);
            evencount ++;
          }
     }
     printf("\n Odd Num: %d \n Even Num: %d", oddcount , evencount );

     return 0;
}

If you are still getting some problem then post your problem here..

vinitmittal2008 37 Junior Poster
# include <stdio.h>
# define MAX 100
int main(void)
{
    int array[MAX],i,n;
    
    printf("\n Enter Array size (1 - %d):",MAX);
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++)
    {
       printf("\n Enter %d value :",i+1); 
       scanf("%d", &array[i]);
    }  
    
    // whatever else you want to do....... 

    return 1;
}

main function returns a integer vaule.. that is why return 1 is used.

vinitmittal2008 37 Junior Poster

ok

# define MAX 100

int main(void)
{
  int array[MAX],n;
  // scan array size from user but it must not be greater than MAX
  scanf("%d",&n);
  // now run your loop from 0 to less than n and scan array values

return 1;
}
vinitmittal2008 37 Junior Poster

it's easier to use but cause you are new then you should use predefined arrays.

vinitmittal2008 37 Junior Poster

if you are not new to C language then you can use malloc or calloc function to create your Arrays..

vinitmittal2008 37 Junior Poster

:)

vinitmittal2008 37 Junior Poster

For Removing a file you can use remove macro defined in stdio.h

int remove (const char *filename);

on success it returns 0, but before removing a file be sure that file is closed.

you want to remove argv[1] after copied to argv[2].

if ( remove(argv[1]) == 0)
   printf("Removed!");
else
   printf("Error Removing File!");

I think it could help you..

vinitmittal2008 37 Junior Poster

hey... please embed your program code 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
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

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

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 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

Hey becka221,

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

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

nice work dude!!

But could'nt get the logic.. :)

vinitmittal2008 37 Junior Poster

Here you went Wrong !!

Are you sure that you will input 80 char long string every time...

while(i!=80)

It should be like

while(array[i]!='\0') // A string in c comes to end when it reaches '\0'

Also you are running a never ending while loop because there is no incrementation of i inside while loop..

i++;

Also this line is wrong

if(array[i]==(('a')||('A')||('e')))

Check for all vovels a,e,i,o,u and make it like

if ( array[i] == ('a') || array[i] == ('A') || array[i] == ('e') || array[i] == ('E'))

Also add condition for 'i' ,'o' ,'u' in the above if statement..

And print

printf("%d vowels, %d characters, %d others\n",vo,co,ot);
vinitmittal2008 37 Junior Poster

can you post your complete code here.... then it would be easier to understand exactly what's going on....

vinitmittal2008 37 Junior Poster

sir, what do you mean by specifying the path, could you give me an example
and i checked the folder it does not have my work saved in it...
thank you

Specifying the path means telling the compiler where you want your File on Disk...

like:
ofp = fopen("D:\\xyz\\myprogram.txt", "w"); // D is Drive Name & xyz is folder name on that drive....

vinitmittal2008 37 Junior Poster

to make a char array
of 2 columns containing strings 49 characters long and
10 rows contaning strings also 49 characters long.

is this correct char ArrayName[10][50][2][50] ??

what i get is you want a char array that have 10 rows and each row contains a 49 char string...
then it could be done by simply
char charname [10][50]