/!\Help in this prog. please /!\

Thread Starter

!!Miss.EE!!

Joined Oct 17, 2007
38
Hi all ,

I have a project in C language ,

I've done every thing , and it gives me 0 error :D

However, I want to check if it works , My part depends on my friend part ,

put I've put here structure and initialized them , but still it didn't work :(,
can any one help me please ~~~~~~~~~~~~~~~~~~~:p

IT WAS A DISASTER >>>> :(


can any one finds where I am wronged please .......
 
Last edited:

Mark44

Joined Nov 26, 2007
628
I've done every thing , and it gives me 0 error :D
All that means is that you don't have any syntax errors, errors in the way you have used C. The compiler can find these easily. You probably have semantic errors, which cause the program to produce incorrect results.
However, I want to check if it works , My part depends on my friend part ,
I'm not sure what you mean by friend part. Does it mean that your friend wrote part of the code?
put I've put here structure and initialized them , but still it didn't work :(,
Instead of telling us just that it didn't work, give us some details, such as the output your program produced.
IT WAS A DISASTER >>>> :(
This is not helpful at all. Provide details about what the program produced as output.

The biggest problem I see right away is that you are initializing array variables before you actually declare them. In the following code snippets you are initializing some fields of the dept and nation array.
Rich (BB code):
dept[0].Dcode=123;
dept[0].Name="EE";
Rich (BB code):
nation[0].Ncode=321;
nation[0].Name="uae";


Later on, in main(), you get around to the declarations of the dept and nation arrays.
Rich (BB code):
int main ()
{
int i,j,k;

per_info personal[1];
dept_info dept[1];
nation_info nation[1];
Also, I should point out that you cannot assign a string constant to a character array variable, as you're attempting to do here
Rich (BB code):
dept[0].Name="EE";
and in the person array. The assignment actually occurs, but what gets stored is the address of the string constant, not the string of characters. To assign a string value to an array variable, you need to use a string function such as strcpy().

Another thing to check is that each call to scanf has a control string that matches the types you are inputting to. Here's one that needs work.
Rich (BB code):
printf("\nDate of birth:");
scanf("%d%*c%d%*c%d",&personal.month,&personal.day,&personal.year);

You have four conversion specifiers (e.g., %d, %c), but only three variables to the right of the control string. With three variables, you need to have three conversion specifiers. Also, the conversion specifiers for character array variables should be %s, not %c (you have %*c).

Same problem in the call to scanf to get the joining date.

If you don't understand how to use scanf very well, it would be better to input to one variable at a time, instead of trying to input to three of them in a single scanf call.

That should get you started on the right track.

Mark
 

Thread Starter

!!Miss.EE!!

Joined Oct 17, 2007
38
yeah thanks MARK ,

I am myself did'nt know my instructior want from all the modefied .... however



printf("\nDate of birth:");
scanf("%d%*c%d%*c%d",&personal.month,&personal.day,&personal.year);


this is to write the DOB in the form : mm/dd/yyyy


BUT the main QUESTION now ... were I should initialize the Departments and natinalitiy structures , and how ....

that what I want to know for now .....
 

Mark44

Joined Nov 26, 2007
628
I absolutely don't understand what you are saying here.
I am myself did'nt know my instructior want from all the modefied .... however
Judging by something you said later in your post, you actually want to do output here, not input. If that's the case, you need to use printf, not scanf. As I said before your control string should have the same number of conversion specifiers (the %d, %c things) as variables.
Rich (BB code):
printf("\nDate of birth:");
scanf("%d%*c%d%*c%d",&personal.month,&personal.day,&personal.year); 



The 2nd printf call below will print the month, day, and year, with slashes between, in this form: 5/21/2008. It assumes that the month, day, and year are stored as int, not strings.

Rich (BB code):
printf("\nDate of birth:");
printf("\n%d%/%d/%d",personal.month,personal.day,personal.year); 



this is to write the DOB in the form : mm/dd/yyyy

BUT the main QUESTION now ... were I should initialize the Departments and natinalitiy structures , and how ....

that what I want to know for now .....
Since you are declaring your struct array variables in main, that's where you want to initialize them.

Rich (BB code):
int main ()
{
  int i,j,k;

  per_info personal[1];
  // Initialize personal variable here

  dept_info dept[1];
  dept[0].Dcode=123;
  dept[0].Name="EE"; // This won't work. Need to use strcpy()

  nation_info nation[1];
  nation[0].Ncode=321;
  nation[0].Name="uae"; //This won't work. Need to use strcpy()

  // and so on...
 
Top