csurfer 422 Posting Pro

All the above listed algorithms are the bests you can find to sort an array of numbers but I would prefer this order for you to start with as you are a starter.

1>Selection sort
2>Bubble sort
3>Quick sort
4>Merge sort

1 Tells you how to start sorting with help from computers.2 takes the same to an higher level and tells you better way of sorting.3 and 4 are the best sorting algorithms available.

Go in the same order if possible.And ya GOOGLING it or searching it on WIKIPEDIA would help you a lot.

csurfer 422 Posting Pro

Not only a structure...You cannot define anything dynamically.
You can just set values to already allocated or defined variables.Even in functions like malloc where you allocate memory dynamically during run time you only allocate memory to predefined or declared variables. Creating a completely new entity is not at all possible.

csurfer 422 Posting Pro

Well I found this thing in your code:

initgraph(&gd,&gm,"C:\\TC\\BGI");

Its normally this way:

initgraph(&gd,&gm,"C:\TC\BGI");

When you are so sure about the libraries you possess then try out the example program given for <graphics.h> that should work fine for a try(As you are using TC).

If not follow this path:
start->control panel->system->advanced->Environmental Variables->System variables->find PATH->Click Edit->

After this DO NOT change anything else just include ; and then your TC path at the end.

Note: To find a solution to your problem you gave us all the details. Only your compiler configuration would be enough and the platform you are running it on.(Graphic details at max).Your other PC details wont be necessary. ;)

csurfer 422 Posting Pro

A semicolon can be useful in some preprocessor commands (probably some bizarre scenario), for example its perfectly valid in a #define statement. In this case we do need to know the compiler and its definition of #pragma because its functionality is not standard.

Well according to my knowledge semicolons are not used in any of the preprocessor directives because of the fact that preprocessor directives are mostly used within the coding statements and the appearance of ";" would mark the end of that statement.

csurfer 422 Posting Pro

I like the function better. I'm having a bit of a mind block about though. I know I have to iterate through arr[17]. But how do I stop at the 4th element, switch to a new array and read the next 4 chars?

Well I respect your zeal to write your own functions but what PRABAKAR said is absolutely right.You can use that standard function given in the library.(Standard functions are given so that programmers can code good programs without getting bogged down by certain stuff.)

If you want to code it your self do this:

//Declare four character arrays or an array as arr[4][5] ie four char //arrays to hold four characters and a '\0'

//Declare an array to take up your input string as str[17] or //something

//Take your input
i=0;
a=0;
while(i < strlen[str])
{
          for(j=0;j<4;)
                    arr[a][j++] = str[i++];
 
          arr[a][j]='\0';
          a++;          
}

The code is self explanatory. I have padded the arr array's 5th cell ie

arr[a][4] = '\0';

so that next time while printing you can just give

printf("%s",arr[a]);

Hope you can code as you wanted now.But I still recommend usage of standard functions when they are possible.

csurfer 422 Posting Pro

Ya I too agree with Ahmed_I that Minesweeper just uses a two dimensional array with mines generated at random.
Then a program is run which takes the present cell co-ordinates and calculates number of mines in all adjoining cells and writes a number equal to number of mines around it.

The later part of clicking and all can be done through some other methods.

csurfer 422 Posting Pro

Hi C experts,
In my code I have got
#pragma extern_prefix (push, "");
Some extern function declarations
#pragma extern_prefix (pop, "");
So that compiler does not prepend anything to those extern functions , I get an error

error #14: extra text after expected end of preprocessing directive

Does anyone know how to fix this syntax error ?

I may be wrong but if this pragma is acting as preprocessor directive then it should not have any ";" at its end. Right?
(Even the error coming is also showing that...)

csurfer 422 Posting Pro

hello

nice help from this site,

pls help me for program

problem :
C program to read a list of names ending on a '$'. Each name ends on '.' and contains maximum of 30 characters. our program must convert the format as indicated in the example below and print the modified list of names. Your program must use files for input and output.

input Output
Ashok Kumar Sinha. Sinha A.Kumar.
Prem Lal Sharma. Sharma P.Lal
Hari Om Prakash Prakash H.Om

pls help

Note : Don't mix up the threads.Your question is different form the present thread so start a new thread or else your question may go unnoticed. And someone with the same problem as yours wouldn't even know where to look for even though answer is here.

Well your question can be dealt as follows:

1>Take the inputs as string.
2>Tokenize the string with strtok and get the constituent strings.
3>Once you have all three parts of the name its only matter of arrangement and converting the First name to its first character.And arranging according to your needs.

csurfer 422 Posting Pro

I just learned pointers in my computer science class and i am having a hard time understanding what they are used for. Are they absolutely necessary to use them when passing arrays from functions ect. or is it just a more efficient way of doing so?

Don't look at the problem in hand,try to see through it ok.

Pointers are nothing but what they literally mean. They just point to things(Here variables arrays etc).
Here in C when we work we have this kind of layout:

Name
Memory
Address

Every memory block we use has an address( got by using &variable ) and we give it a name ( the variable name we use most of the time ).
We can easily pass these kind of (single unit) types to functions as arguments easily.But when it comes to an array it is not a single unit as such. It is a unit formed of similar units taken together and just think how difficult it would be to pass each unit of the array to function as array[0],array[1] ( If its a large number as array[1000] or something we are doomed :D )
So in case of arrays what we do is we send something which points to the memory unit where the array starts and access it.

Once you dive to the depths of "C" you wont find a topic more beautiful than pointers.Just keep your chill and learn what has …

csurfer 422 Posting Pro

hi
i just want to know how to write a c program for heap sort. please help me

Do you know how to sort numbers according to Heap Sort manually on paper ? I hope your answer is yes,if not learn that first without it you cant understand how to make computer do it (code it).Go through these first:
1>How to construct a heap tree?
2>What number should be deleted or removed from tree to get numbers sorted?
3>When a number is removed what is the process of removal and how is the heap affected?

csurfer 422 Posting Pro

Do you need all those files in memory at the same time? char arr[15][100] will only hold 15 strings, each string can contain a maximum of 99 characters + null terminator. So about all you might get in that array is the first line of text that is contains in 15 files.

You could use linked list of linked lists instead of a simple array. With that the program can read the files only once and still get they dynamic allocations you are looking for.

For example you could use a structure something like this:

struct LINK
{
    void* data;       // primary data attached here
    viud* extradata;  // this could be another linked list
    struct LINK*next;
};

Ya to make the code compatible with more number of files and characters how about doing this "ANCIENT DRAGON" ???

char **array; // A 2d array pointer
int nof; // No of files required
int noc; // No of characters required in the string

// Scan values of nof and noc

array = ( char * ) malloc ( nof * sizeof( char *));

for(i = 0 ; i < nof ; i++ )
{
        array[i] = (char *) malloc ( noc * sizeof( char ));
}

@RexxX

It was this thing I had in mind when I posted you my earlier reply.I am not very sure of the above code but I think I am correct up to a major extent and ya don't forget to free memory at the …

csurfer 422 Posting Pro

Well in my view allocating array[15][100] would be faulty as that may lead to array overflow and illegal memory access in some cases(Because here you are handling files).
And not all files are longer there may be small files which may not use most of the allocated memory or some files which may need more than allocated memory.
So I would suggest its better to scan the file twice know the number of columns and then use malloc.

==> Here,by scanning the file twice you are decreasing the time complexity but in return you are getting a safer,more memory efficient program to run.

csurfer 422 Posting Pro

Well I tried executing your code in DevCPP compiler and it worked fine for me.Gave the required output.I too agree with "Salem" may be its just a matter of luck and compiler sometimes.

csurfer 422 Posting Pro

Hey,
does anyone know if it possible to have something like

#DEFINE NUM_DEC 4

printf("This is your value:%.NUM_DECf\n");

thanks in advance

Its impossible because anything other than data type specifiers and escape characters within double quotes of printf function is treated as string or character constant and is printed as it is in output.

csurfer 422 Posting Pro

Thanks for the reply.
If this gives all the prime numbers less than 1000000,how can i modify this to get the largest difference between two consecutive prime numbers?

Well you need to know one thing very clearly that your program is not generating prime numbers up to 1000000 as you have mentioned. Your program just generates prime numbers till 1000 i,e sqrt(1000000).

And to find the max this is what you need to do:

int i=2,j=3,max=0;

// Setting two variables i and j to first two prime numbers
// Setting max difference to 0 to start with

while( j <= N ) // To ensure higher prime doesn't go beyond N
{
        if( (j-i) > max )   //If this difference > Present max value
                      max=j-i;   //Assign this difference to max 
        
        i=j;   //Shifting i's value to next prime i,e j 
        j++; //Increment j by 1 so that its value changes
 
        while( prime[j] != true && j < N ) j++;
        // Move j's value till it reaches next prime or N
}

printf("Maximum Difference between consecutive prime numbers is %d",max);

Hope you can get the above code.(Its quite cumbersome) This will definitely do your work.

csurfer 422 Posting Pro

@JONZ

Your question doesn't specify your need correctly.Well I could frame two questions out of it. So answering them.

1)How to create stacks and trees?

Stacks can be created using many methods. By Arrays, using a variable to act as top indicator. By Linked List, using a node pointer to act as top indicator.

2)Where can you apply stacks and trees?

Stacks can be applied for various applications.
Ex : Reversal of a string.
Trees are applied where ever solution to the problem needs branching of decisions at various levels according to requisites.
Ex : T9 dictionary in mobiles.

csurfer 422 Posting Pro

There are many flaws in your code as the multiple number of if's used and one need to change many lines of the program to get the required output.Try to write program such that number of stars can be varied without going through entire program. There are many ways to code it in a better way one of them already shown above by "Prabakar".
I will just stick to the concept of visualization I told earlier and write program as shown below:

#include<stdio.h>
#define MAXSTAR_LENGTH 9 //Number of stars you want(some odd number)

int main()
{
    int i=0,n,mid=MAXSTAR_LENGTH/2,lcount=0;

    while(lcount<MAXSTAR_LENGTH)
    {
	      for(n=0;n<MAXSTAR_LENGTH;n++)
	      {
			  if(n >= mid-i && n <= mid+i)
			  printf("*");
			  else
			  printf(" ");
	      }
	      printf("\n");
	      lcount++;
	      
              if(lcount<=mid)
	                      i++;
	      else
	                      i--;
    }

    return 0;
}

This is not the best program you can write for the above requisite but this one goes with my earlier idea of a space and filling lines with "*" or " ". So posting this.

csurfer 422 Posting Pro
void displayUnion( iUnion );

union integer_union
{
      char c;
      short s;
      int i;
      long l;
};

typedef union integer_union iUnion;

int main()
{
      iUnion value;
     
     //code continues

Hey in your program you are declaring a prototype of function display as shown below:

void displayUnion( iUnion );

And passing an argument of type iUnion to it when a union of type iUnion is not even defined.Hence at that point of time it defines the function in some way but not knowing the real structure of iUnion only.

Try this:

union integer_union
{
      char c;
      short s;
      int i;
      long l;
};

typedef union integer_union iUnion;

void displayUnion( iUnion );

int main()
{
      iUnion value;
   
      //code continues
csurfer 422 Posting Pro

thats a great idea but I m a beginner and I'm still not using arrays just loops.

That was an idea you can just use loops not arrays ok... Just loops
is enough.
Outer loop to count the rows and inner loop with some trick of yours within a if statement may be to print the *'s and " "s.

csurfer 422 Posting Pro

please write a programme to sort array of integers using quick sort

I hope you have read this community rules. Everyone here is capable of solving this thread but we are here only to help people who really are struggling to get knowledge and are working themselves.Even we are learning in the same way...

ddanbe commented: Even we are learning in the same way... Well said! +4
Salem commented: We can but try.... +28
csurfer 422 Posting Pro

ajhais,
It should actually be a Breadth First Search (BFS), not a DFS.

No its a DFS only not BFS : You don't need to move to all points adjoining a point,if you wanted to do that then BFS is required. But in this problem we want to move through different blocks taking steps moving away from start point so we need DFS where once we reach a point then we need to take a step towards destination not worrying about the other points reachable from that point.
After all evaluation we need to find the shortest path.

csurfer 422 Posting Pro

Hey all the beautiful help given to you above should increase the interest in you to build the program.The help given above is splendid read it again.

Well try this:

012345678
0123*5678
012***678
01*****78
0*******8
*********
0*******8
01*****78
012***678
0123*5678
012345678

If you assume the space to be a linear array from 0 to 8 as shown above which can be filled by * or " " then see the pattern you need to fill stars in and " " in and run your code. The above pattern might help you visualize it.

csurfer 422 Posting Pro
struct restaurant_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
}rest[8]={"ABC","Makati","150.00","Thai"},
	       {"DEF","Pasay","250.00","Asian"};

in this program when you type, example you type asian all the asian food will be shown

Hey be descriptive in your needs and ya if I am not wrong then the initialization of structure is not correct.For every array type you need to declare like this:

struct restaurant_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
};

struct restaurant_t rest[8]={{"ABC","Makati","150.00","Thai"},
	       {"DEF","Pasay","250.00","Asian"},{.......},{.......},{.......},{.......},{.......},{.......}};

or

struct restaurant_t {
	char name[20];
	char add[20];
	char type[10];
	double cost[5];
}rest[8]={{"ABC","Makati","150.00","Thai"},
	       {"DEF","Pasay","250.00","Asian"},{    }, {   },{  }};

Not the way you have done.

csurfer 422 Posting Pro

can you give an example of sorting?
in c..tnx!

There are many : Bubble Sort,Merge Sort,Quick Sort.

And yes "can you give" is one of the phrases you should use in this community only after you yourself do some work on it.Hope you have done it.

csurfer 422 Posting Pro

Hi.. thanks for the solution. I was thinking of going with the same.. How can we approach this problem if the map is dynamic.. that is if some obstacles can randomly appear in the map.. We actually need to code a bot for battle city game..

Well if you know DFSearch then you will know that each time the whole array gets passed as one of the function argument to the recursive DFSearch function and checking is done in a for loop.
So before checking in the for loop in case of dynamic obstacles just change the particular

Array[<i co-ordinate>][<j co-ordinate>] = 0;

before passing the array to next DFS function recursively.

csurfer 422 Posting Pro

Given a n*n grid with free spaces and obstacles in the form an n*n integer matrix. We need to find shortest between any two given points (x1,y1) and (x2,y2) through the free spaces. We are not allowed to move in diagonal. Please help me figuring out an algorithm for doing this.
Thanks in advance.

Well this is one of the many ideas you can apply to this problem.Here it goes:

Firstly take the value of n for your n*n grid from the user and also a valid grid structure input where free spaces are represented by 1's and obstacles are represented by 0's.

Your array for 4*4 might look like this:

0 1 2 3
0  1 1 0 0
1  0 1 0 0  
2  1 1 1 1
3  0 1 1 1

Now pass this array as input array and (x1,y1) as input co-ordinate
and (x2,y2) as the destination point to be reached for a "DEPTH FIRST CHECK" graph algorithm.

Actually the best graph algorithm to find the shortest path between two vertices is "DIJKSTRA'S ALGORITHM" but here as you are just moving one step to top bottom left or right only and all steps are of same length you can use Depth First Search only to solve your problem.

csurfer 422 Posting Pro

Apart from the heavy memory consumption problem stated by "death_o_clock" which need to be corrected,your program has other major errors.

1> picked[8] can carry flags only up to integer 7 and

for (i = 0; i < 9; i++)
         picked[i] = 0;

will itself give error.Therefore picked[9] is the declaration you should make for your idea to work.

2> Other major flaw is in code

for (i = 0; i < 9; i++)
    {
        value = rand () % 9;
        if (picked[value])
            i--;  // already picked.  for-loop increments, so decrement here
        else
        {
            array[i] = value;
            picked[value] = 1; // hasn't been picked yet.  Assign to array,
                                // flag as picked.
        }
     }
     
     // display
     for (i = 0; i < 9; i++)
        printf("Values in the array are %d\n", array[i]);   
       getch();
      return value;

You have taken so much time to generate 9 random numbers 0-8 ( rand() % 9 )such that if a number repeats then it is not considered and again a number is generated a random.
After all this effort you are just sending the random number which is generated at last back to main.
This is just as calling :

for(i=0;i<9;i++)
       s=rand()%9;

in main itself.Ultimately you are just getting the random value generated on the ninth looping.

csurfer 422 Posting Pro

Well your requisites aren't clear so mention them in detail.

Apart from it you can initiate a char array and then get the input through simple scanf() function.

Then use strtok() with array address and space as delimiter to get the first token and then loop over and get the other tokens by using strtok() with NULL address and space as delimiter.

Both your requisites (or at least what i could make of them)are satisfied.

csurfer 422 Posting Pro

Related to: n=(NODE)malloc(sizeof(struct node*)); Casting malloc is not necessary if the proper header file stdlib.h is included.
Fail to check for a successful return of allocated memory.
Fail to release dynamic memory.

Yes the code is not complete it lacks other details too like the actual usage of pointers to other important things has not been shown.

it should end with free(n);

and should possess error check as you said.

Can you be a bit more descriptive in your explanation of first point.?

csurfer 422 Posting Pro

Well I am not able to point out your mistakes exactly but this code does work:

#include<stdio.h>

struct node{
int a;
char b;
};

typedef struct node * NODE;

int main()
{
NODE n;
int *in;
char *ch;
n=(NODE)malloc(sizeof(struct node*));
in=&(n->a);
ch=&(n->b);
*in=10;
*ch='a';
printf("%d %c",*in,*ch);
return 0;
}

I think the way in which you have defined the typedef of the struct is wrong.

Apart from that the initialization of pointer for struct or creating the sruct of some type as

<struct name> variable;

doesn't make the structure usable. You need to allocate memory for the structure using malloc as mentioned above.

csurfer 422 Posting Pro

The real problem here is recognition of a word. And as we all know word is a linguistic concept and we cannot be fool proof while programming for such concepts.

The only way I see is to implement AGNI's method for the start and move assuming the sentence is a grammatical English sentence where we can apply :

NO of words = No of spaces from start till '\0' + 1

You can alter "Input String" as "Input a Simple English sentence" or something as inputs generating errors can be written infinitely.

Secondly you can take your input string as:

char String[50];
printf("Input a Simple English sentence");
scanf("%s",String);

Rather than taking it character by character.

csurfer 422 Posting Pro

A small addition to both the codes mentioned above.

The rule for being a Prime Number in maths states that a number is prime if it cannot be divided by any number (actually any prime number ) <= the square root of the number given.

that is:

for( i=2 ; i <= (int)sqrt(num) ; i++)

hence if you modify code as

#include<math.h>
//other includes

int main()
{
//your declarations

int sqr,prime=1;

//Accepting the number

sqr=(int)sqrt(num);

for(i=2;i<=sqr;i++)
{
                   if(num%i==0)
                   {
                                prime=0; 
                   }
}
if(prime)
                 printf("Prime number");
else
                 printf("Non prime");
return 0;
}

By applying the above mentioned rule you can reduce the number of comparison to nearly half and hence the efficiency increases highly in case of large numbers. Other mistakes have been rectified in post by "lucky chap".

csurfer 422 Posting Pro

csurfer: Do you always just repeat what other people have already said?

I am sorry if you felt so but when i started replying to this thread your post was not there and deleting a post is not in my hand.

csurfer 422 Posting Pro

Line no 79 84 even though not wrong are not needed...
Just lattice[j]++ or -- is enough.

line 21 and 24:

lattice = malloc (row * sizeof(int *));

lattice[i] = malloc(col * sizeof(int));

I may be wrong but i feel the memory allocation of single * and double * pointers are not done properly.
Here lattice is actually **lattice and lattice is *lattice and are different.

csurfer 422 Posting Pro

Well as much as I have seen your switch is not doing any thing other than going to the case n where n=lattice[j] and doing
table[n][1]=table[n][1]++

And with this thing in mind if the sole purpose of your switch is what I have stated above then your whole switch statement can be substituted with just one statement.

table[lattice[j]][1]++

csurfer 422 Posting Pro

All header files are taken from the include directory. May be the compiler is not responding because your newly created header file may not be in its search path.

csurfer 422 Posting Pro

malloc(<size>) just allocates a memory space for the size specified and returns a void * pointer pointing to the starting of the allocated memory block.
It returns a void * pointer (so that it can be type cast to any pointer type) and as you know void * pointer itself cannot be used to dereference any variable.So we need to typecast it according to our needs.
Example:

struct node{
int a ;
char b;
};
typedef struct node * NODE;

int main()
{
//Some code

NODE temp=(NODE)malloc(sizeof(struct node));

//Some code
}

General form:

<req>*<variable> = (<req>*)malloc(<size>);

csurfer 422 Posting Pro

malloc not freed and Array overflow errors as indicated by Aia should be checked and the error over flow in line no 64 causes error in every compilation and hence comes in notice.

But the same Array overflow error in Line 135 comes over only in certain cases and hence ought to be considered.

csurfer 422 Posting Pro

I tried your original C file Racenite.c on Windows OS on TC compiler and it is running fine without errors. And no display problem too.

csurfer 422 Posting Pro

Well here is a code in which you can generate numbers from 1 to 1023 i.e all numbers that can be represented in 10 bits.This is just one of the implementation and there are several other simpler ones too...You wanted access for all the bits so this is one way.You can make the changes needed and implement the same code for any higher number too...

#include<stdio.h>
int main()
{
     int i,j,num,sym[10]={0,0,0,0,0,0,0,0,0,0};
     for(i=1;i<1024;i++)
     {
                      num=i;
                      j=9;
                      while(num>0)
                      {
                                  sym[j--]=num%2;
                                  num=num/2;
                      }
                      printf("%d - ",i);
                      for(j=0;j<=9;j++)
                      {
                                       printf("%d",sym[j]);
                                       sym[j]=0;
                      }
                      printf("\n");
      }
      return 0;
}
csurfer 422 Posting Pro

Ok try to print this as it is:

a,b
aa,ab,ba,bb
aaa,aab,aba,abb,baa,bab,bba,bbb
....
..
.

Upto the line user wants.I hope you can see the patter.Its coefficients of the expansion ( a + b ) ^ n.User will give the value of n and you need to print upto that line. Involves only looping.Try this.

csurfer 422 Posting Pro

Hey I feel there are some errors in your posted code:

int main(int argc, char *argv[])/*command line input*/
{
int len;
char *t[10];
len=strlen(argv[argc-1]);
temp[0]=argv[argc-1]
if(strstr(t[0],"c"==NULL)/*to check for a c file input*/
printf("Not a c file");
else
printf("C file");
}

In line 6 and 7 it should be as

t[0]=argv[argc-1];
if(strstr(t[0],"c")==NULL)/*to check for a c file input*/

And also I didn't get the usage of your "len" variable.You haven't used that for any productive usage.

And ya in LINUX based platforms a.out is not just an output file. The source file without any errors is correctly compiled to create an object file. This object file when loaded and linked properly an executable file is created which can be run and is called by a general name in LINUX called a.out.

csurfer 422 Posting Pro

Include your codes within the code syntax.Its really hard to analyze it without it.Have a look at the code tags.

csurfer 422 Posting Pro

Only the IEEE notation of floating point is able enough to hold the planks constant. As it is a very small number and the first non zero number comes only after nearly 33 digits and so your number gets truncated to first 6 places only. Therefore 0.000000 and as soon as you remove the exponential value it becomes a normal floating point number and hence gets displayed.
Try %e for exponential display but you need to separate the exponential part and involve it separately or else even with all your effort answer will just be 0.

csurfer 422 Posting Pro

In my knowledge there is no such inbuilt way in C language to get the last modified time.
The file doesn't hold such information even in Linux platforms.The file table has all such information but accessing it through just C language statements is doubtful.
May be you can include a module to write file access time at the beginning of the text file and always start access from a later point.

File Start:Access time____|Text of file-----------------------------------EOF

Always writing the file access time at the beginning of the file whenever the fopen() for the file is called.And then using fseek(<Some definite value>) and writing the file text from that point.

csurfer 422 Posting Pro

This isn't so easy.Even long integer cannot hold the complete length of the input you are assuming so we need to split the number into digit basis and proceed.

1>Take three array's A , B and C of size 100 each and initialize all their values to 0.

2>Take the input as A[0]=Units place of 1st number,A[1]=Tens place of 1st number and so on...(The same path to be followed for 2nd number with array B).

3>Take a int variable carry which is set to 0 initially.

4>if(A>B)
perform C=A-B;
// Remember carry is 0 only it is not manipulated

5>if(A<B)
set carry=1;
A=10+A;
now perform C=A-B;

6>In every loop check if carry is 1 (that is in the previous instance required a carry for subtraction) if not continue with step 4 or 5 which ever is proper.

7>If carry is 1 then perform:
A=A-1; // i is present count of loop
And then move on with step 4 or 5 which ever is proper

I suppose this is enough to give you a start.Now go on building this idea or a better idea of your own.(This idea still needs work and is not complete.)

csurfer 422 Posting Pro

@ahamed101:

In my knowledge your usage of void * pointers are wrong.

The sole purpose of introduction of void * pointers in C is to include the concept of polymorphism and the basic limitation of void * pointers says that it cannot be dereferenced.

that is:

int *p,x=10;
void *v;

p=&x;    // Correct
printf("%d",*p);  //Correct
v=p;   //Correct

printf("%d",*v);  // Error as void* pointers cannot be dereferenced

Mostly they are used as intermediate elements in type casting of pointers.BUT CANNOT BE USED TO REFER TO VARIABLES DIRECTLY.

csurfer 422 Posting Pro

Excellent usage of the "LOCK" concept of OS in a very simple way in coding ANCIENT DRAGON. GREAT !!!

(Might be a bit difficult for starters to comprehend in the way it ought to be taken.)

csurfer 422 Posting Pro

Yes you need to remove the usage of "goto" statement.Below is one of the several ways how you can remove the goto.

repeat:

printf("\nEnter current year:");
scanf("%d",&cy);

printf("\nEnter current month:");
scanf("%d",&cm);

printf("\nEnter current date:");
scanf("%d",&cd);

printf("\nEnter birth year:");
scanf("%d",&by);

printf("\nEnter birth month:");
scanf("%d",&bm);

printf("\nEnter birth date:");
scanf("%d",&bd);

if (cy<=0 || cm<=0 || cd<=0 || by<=0 || bm<=0 || bd<=0)
{
               printf("\nEnter correct date");
               goto repeat;
}

You can change this as:

while(1)
{
             //Your code before the if.

             if (cy>0 && cm>0 && cd>0 && by>0 && bm>0 && bd>0)
            {
                    break;
            } 
            else
            {
                    clrscr();
                    printf("Enter correct date.")
            }
}

As you can see until you get a correct date you will be within while loop only so change your code like this its better coding style as all have said.

And your code doesn't have any problems on first look.

csurfer 422 Posting Pro

The real essence of C is in the discovery of C by yourself so try to discover more and read books like "ANSI C" by Kernighan and Ritchie.

1.Try to print the Pascal's Triangle (This requires only looping and a bit of array knowledge.)

2.You need to start imagining and create problems of your own from now on.Best of luck.