Adak 419 Nearly a Posting Virtuoso

"archive" is a string, and so scanf("%s", archive); is correct. Remove the ampersand from in front of your "archive", in that line of code.

Same is true for "original file", in line #9. Remove the ampersand.

The address will be correct, but the pointer will be of the wrong type.

You need three pointers to work with three files simultaneously. You are using four now, which is prone to errors, and confusing. Get the logic straight in your mind.

In the while statement, "n = " is unnecessary.

Adak 419 Nearly a Posting Virtuoso

Very interesting Brian, thanks for sharing! ;)

And welcome to the forum. :)

Adak 419 Nearly a Posting Virtuoso

Change your %f, %s, %s to %f%*c %s%*c %s

The %c handles the ',' char, and the * modifier in front of the c, should tell fscanf(), not to store the char.

fscanf(filePointerName, "%f%*c %s%*c %s ", &myFloatVariable, myString1, mySring2);
Adak 419 Nearly a Posting Virtuoso

This is a C forum, not a C# forum - move down the forum list just a bit more.

Adak 419 Nearly a Posting Virtuoso

Any C tutorial would include this. Google up a bunch, and have at it. If you have a particular question, post up your attempt to do it, and let's see what the particular problem is.

There are scores of good C tutorials on the web. Which are appropriate for your level, and preferences, is something you can best answer.

Adak 419 Nearly a Posting Virtuoso

You'll have to give more info than that!

Not related to the "Mummy" are ya? ;)

Adak 419 Nearly a Posting Virtuoso

If you want sorted strings, then you have to compare them as strings, not as individual char's. You can see the problem:

Abbey should sort out lower than Cathy, but when you are comparing the 'b' in the second letter of Abbey, with the 'a' in the second letter of Cathy, it won't.

You need to #include <string.h>, and then use strcmp(string1, string2).

If strcmp() returns > 0, then string1 is higher (greater) than string2. If strcmp() returns 0, the strings are equal, and if strcmp() returns < 0, then string1 < string2.

in pseudo code:

if((strcmp(string1, string2)) > 0) 
  string1 > string2 so make your swap code
  right in here
end if
Adak 419 Nearly a Posting Virtuoso

I applaud your energy, but you don't understand what programming is all about.

The rare goto is OK, but there's no need for them in TTT. C (and all programming languages to some extent), are meant to be a concise and efficient way to do something. Where accuracy is paramount, and a good interface for the user is critical, but efficiency and clarity are also important factors.

You didn't design this program, as much as you created more code, until you worked it out. I did the same thing (coded a very long TTT game), once upon a time.

Now that you know the game better, see if you can knock it down to 300 lines of code, or so. That's still a long TTT game code length, but a great improvement. ;)

This time, use functions, and no goto's!

Adak 419 Nearly a Posting Virtuoso

Perhaps the easiest way of doing this is to use

fgets(charArrayName, sizeof(charArrayName), stdin);

to get the number into a string format. Then just "walk" the charArrayName[] char by char, and add up the values as you go (into an integer variable). For your answer, remember to show it using %d, and not %c.

(Each char needs the value of '0' subtracted from it, to get it's integer equivalent, as Jonsca nicely noted, above. )

There are other ways: such as peeling off each digit one at a time, but they are not quite as simple.

If you aren't familiar with fgets() yet, check it out - it can be very useful in all kinds of programs.

Adak 419 Nearly a Posting Virtuoso

There's no way to use a function that only takes one key input, and use it for to input an integer. No, since an integer might contain several digits.

You're asking if there is a trash can, that can haul the garbage truck. Clearly not.

Adak 419 Nearly a Posting Virtuoso

Why not have the user input an integer, instead of a char, (as mentioned above), and use a do while loop, instead of a while loop? That will put the test for what the user entered, AFTER they have entered the loop, instead of right at the top of it.

(This can be done with a while loop, but the logic has to be changed. It's more intuitive to use a do while loop, for clarity.)

Adak 419 Nearly a Posting Virtuoso

Without knowing you, your ability in C and the sciences, or your class, I don't see how we can be of much help.

The start must come from you! Look at things on sourceforge.net, and google up other idea's for a project, as well. Talk to your classmates, etc. What kind of projects have people in your level and school, done in the past? What are you interested in?

Get on it. We can help you with the code, but the initial idea -- no. Only you know yourself, and your instructor, and what kinds of things would be acceptable.

Adak 419 Nearly a Posting Virtuoso

If the test portion of the while(test in here) doesn't resolve to 1 (true), then the inner part of the while() loop will not be entered by the program.

So, is t[jcs] > 100, right at the top of the first loop?

And somewhere in the while() loop, you want to increment a variable (i is the standard syntax, but any integer variable name will work:

i=0;
t[i] = 99;
while(t[i]<100) {
  printf("i = %d", i);
  ++i;
  t[i] = getchar();
}

Without the ++i, the program would always put one value, right on top of the other one, in t. Be careful not to confuse the value of t with the value of i.

Welcome to the forum, TomaCukor! ;)

Adak 419 Nearly a Posting Virtuoso

Did you forget to open the file? ;)

fp = fopen("myfileName", "r");
if(fp==NULL) {
  printf("Unable to open the file\n");
  return 1;  //or use exit() if needed
}

feof() may repeat your last value, check your return type from fscanf() and if it's less than it should be, break out of the input from the file loop.

You know that so far, your code hasn't printed anything onto the screen. ;) That guarantees a blank screen from your program.

As far as the number of rows problem. What range of numbers are you dealing with?

Adak 419 Nearly a Posting Virtuoso

Consider the number 123:

while number is greater than 0 
  one = 123 % 10
  number = number/10  //remove the digit in the one's place from the variable number.
loop

That's all there is to it. It peels off the digits, one by one, from the right hand side. Count the number of times it loops, if needed.

Adak 419 Nearly a Posting Virtuoso

Each structure has it's advantages - and disadvantages. It's like what you drive. You'd want a race car for racing (great for speed and handling), but a diesel truck for towing (loads of low end torque), the heavy loads.

Adak 419 Nearly a Posting Virtuoso

So say you have an array var[100]

and you have only filled the array up to var[50] ... you can not insert a new value into var[51] ? Im sure or I know you definitely can, because I have done it.....I just don't know how to do it for a struct array say if you have 4 different variables.

fscanf(fp, "%s", structName[51].stringMember);

Is the general way to approach it, but consider that:

1) 51 would normally be a loop variabe, like i, instead of a hard coded number like 51
2) While strings just need a string name as their address, numbers and single char's would need the usual & prepended before the structName: &myStructName.myNumberOrChar

While linked lists are a lot more flexible, they are also a lot more difficult to work with, for beginners. Until you're really comfortable working with structs and C in general, I'd avoid trying to work with linked lists, except as learning exercises.

You need to re-read or watch another tutorial on-line, about using structs. You can't work successfully with an array of structs, if you don't know how to work with a single struct, and it's various members, with some competence.

Good luck!

Adak 419 Nearly a Posting Virtuoso
#include <stdio.h>
#define MAX 20

/* prototype your struct in global scope, above main() */
 struct company
 {
    float east,north;
    char name[20],place[20];
 };


int main(void) {
    
    struct company site[MAX];  //instantiate it in main() - good

    FILE*file;
    int i=0;

    file = fopen("companies.txt" ,"r");

    while(fscanf(file,"%s %s %f %f",site[i].name[0],site[i].place[0], &site[i].east, &site[i].north)) == 4) { //while fscanf() returns 4
       //feof isn't what you'd like - don't use it.
       printf("%s %s %f %f\n",site[i].name,site[i].place,site[i].east,site[i]. north);
       i++;
    }
    fclose(file);
    
    return 0;
}

My input file is:

Ikea Nottingham 0.1 0.1
Tesco Lincoln 0.2 0.2
Asda Leicester 0.3 0.4

Try that - I didn't compile and run - excuse any minor bug.

Adak 419 Nearly a Posting Virtuoso

I beg to differ. malloc is defined in some implementation-defined library and declared in <stdlib.h>.

Well, I figured he was going for "alloc.h", since he's just one letter off. Either header file (alloc.h or stdlib.h), will have the needed declarations:


malloc Allocates memory.

Syntax:
void *malloc(size_t size);

Prototype in:
alloc.h stdlib.h

Remarks:
malloc allocates a block of size bytes from the memory heap. It allows a
program to allocate memory explicitly as it's needed, and in the exact
amounts needed.

The heap is used for dynamic allocation of variable-sized blocks of memory.
Many data structures, such as trees and lists, naturally employ heap memory
allocation.

All the space between the end of the data segment and the top of the program
stack is available for use in the small data models, except for a small
margin immediately before the top of the stack.

This margin is intended to allow the application some room to make the stack
larger, in addition to a small amount needed by DOS.

In the large data models, all the space beyond the program stack to the end
of available memory is available for the heap.

Return Value:
On success, malloc returns a pointer to the newly allocated block of memory.

If not enough space exists for the new block, it returns null. The contents
of the block are left …

Adak 419 Nearly a Posting Virtuoso

A few suggestions:

malloc() is defined in the include file "alloc.h", not "malloc.h". ;)

Without the stdio.h include file, I'm not surprised you're having problems opening files and such. ;)

After you malloc() for an array (especially after such a large one), be sure to check the returned pointer address to be sure the request succeeded, and is not NULL.

btw, the return addy from malloc() doesn't need to be cast, 99.9% of the time.

Adak 419 Nearly a Posting Virtuoso

First, dice IS plural - die is singular. There is no "dices".

Sure, you can check each char in the string, to see if it has only certain char's. A check function might look like this:

/* where 5 is the size of the input array. */

int checkStr(char input[5]) {
  int i, good=0; //assume input is not good
  char c;
  for(i=0;input[i]!='\0';i++) { //'\0'= end of string marker char
    c=input[i];
    if(c!='x' && c!='X' && c!='-')
      return good;
  }
  good=1; //if you reach here, then input must be good
  return good;
}
Adak 419 Nearly a Posting Virtuoso

I know Perl is famous for "batteries included", but C is famous for rolling them little batteries right along, as well. ;)

If you're going to have to re-write it, consider just using C.

Adak 419 Nearly a Posting Virtuoso

I suggest using chess fonts - google, download them.

For a 2D chess board, a console window will be OK, but the visual quality of the pieces really suffers if you don't have chess fonts installed.

Using something like Winboard (a chess program interface for chess playing programs without them), could be an easy option.

For all things chess computer related:

openchess.com and talkchess.com

Adak 419 Nearly a Posting Virtuoso

The thing is, there aren't too many programs that don't need a console window, at least.

Oh! I know one - a key logger!!

No, I won't be helping you. ;)

Adak 419 Nearly a Posting Virtuoso

It's NOT a problem with LCD monitors. I use turbo C 1.01 all the time, and have an LCD monitor (Samsung), and it's fine. The OUTPUT is the same, an LCD monitor just uses it for a different device, downstream.

It's also NOT a NVidia card compatibility problem. I have one of those also - no problem. They are backward compatible with the old VGA standard that Turbo C supports.

There are two steps to making this work - but the first one should already be done for you, but check it anyway:

1) Click on the Options --> Linker in the TC IDE (where you might see your code) You should have some items in there that are checked with an [ X ]. Be sure NOT to mess with other settings, but see that Default Library and Graphics Library are [ X }'d.

2) Move these two files, into your C:\TC\BIN directory:
EGAVGA.BGI
EGAVGA.OBJ

The EGAVGA.BGI file is required. The EGAVGA.OBJ file just helps speed things along

These two files are in the default directory: C:\TC\BGI

Now run this Borland Turbo C example program, and see if it works for you. It simply draws a white diagonal line, on a black graphics screen.

Note especially the code it uses! Put that code into your graphics program, instead of the current "C:\\TC\\BGI" directory that you're using now.

Salem is really a fine programmer, but refers to Turbo C …

Adak 419 Nearly a Posting Virtuoso

I believe what you want is available from the programs that create archives. I'm talking about zip, rar, pak, and all the rest.

Google up a website that deals with these archive makers and their algorithms, and dig in. I'd be sure to include Wikipedia in that search. Whatever content they have should be a great introduction to what you want to do.

Adak 419 Nearly a Posting Virtuoso

Changing the name of the array might confuse humans a bit, but the compiler just needs the address as a parameter. You can change the name in the parameter, and that's fine. But you can't change the struct member name, or the size of the member, etc.

If you want to do something like this:

StudFile gpa[CLASS] = {5.50, 2.22, 3.33, 4.44, 9.99, 6.66, 7.77, 8.88, 1.11};

You need to fill in all the other member values, for the struct, or specifically denote which member you're changing. Again, it's all a matter of being specific about which value, goes to which struct member.

If you want to assign just one member, use a for loop:

for(i=0;i<Somenumber;i++) {
  if(i==0) 
    arrayOfStruct[i].member = 5.50;
  
  //etc.
}

No need to go through the index, for this assignment. Just do
your sorting, later.

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

    printf("\n Enter Array Size: ",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("%3d ",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++;
      }
    }
    return 0;
}

Your code isn't stopping. It just finishes - you never added the print statement for how many even and odd numbers you had in the array.

Add that, and it should be fine - if not, post back. Don't you know how to single step through your program yet?

That's a MUST to learn, and right away. You have some real work to do to get yourself up to speed on this. Get cracking, dude! ;)

Edit: With n, you aren't setting up the size of the array - it has MAX number of elements. You are setting up how many elements your data will have, in the array. You don't want to go working with …

Adak 419 Nearly a Posting Virtuoso

You need opening and closing braces around the body of the last for loop.

Opening - line 29
Closing - on line 43

Any multiple line statement block of code, requires braces around it.
For example:

for(i=0;i<3;i++) {
  printf("\nThis is loop number: %d", i+1);
  printf("And this is being printed only once without the braces");
}
Adak 419 Nearly a Posting Virtuoso

Mosaic has kindly made several suggestions about your code problems.

Let's look at your code.

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

    printf("\n Enter Array Size: ",MAX);
 
    scanf("%d", &n); // User enters Array Size
 
    for(i = 0; i < n; i++)
    {
       printf("\n Enter %d value: ",i+1); 

     // things like /n don't go inside scanf()
       scanf("%d", &array[i]); // Allows user to enter values into the Array
   }
    
    putchar('\n');
    printf("\nArray Values: ");
    for(i = 0; i < n; i++)
    {
       printf("%3d ",array[i]); //Prints out the array
    }
     //**************************************//
  
    // whether the values in the array are odd or even.
    for (i = 0; i < n; i++) // This section of the code is meant to determine 
       

/* 8888888888888888888888888888888888888888888888888888
move these two lines to ABOVE the start of this for loop it's inside of now 
    oddcount = 0;
    evencount = 0;

They don't belong down here.
8888888888888888888888888888888888888888888888888888
*/
       if (array[i]%2 != 0)  //removed your semi-colon
       {
          printf("\nThe number %d Is Odd.\n", i);
          oddcount++;     
       }
       else {  //added a brace
          printf("\nThe number %d Is Even.\n",i);
          evencount++;
       }  //and it's matching brace

    } //end of your for loop
    getch();
    return 0;
  }
}

That has several corrections and a note for you to move some assignments, so make that move of the assignments, and see if that isn't better.

You'll want to add the print statement for the number of odd and even numbers that were found, near the end of the program,

Adak 419 Nearly a Posting Virtuoso

You and your semi-colons!

if (array[i]%2 != 0); //delete this semi-colon!
Adak 419 Nearly a Posting Virtuoso

The semi-colon inside the << >> is incorrect. Delete it.

the red closing brace is something that will cause a lot of headaches if you keep putting them on the end of a line of code.

Don't do that -- they get over-looked. Employer's dislike it, for that reason.

Adak 419 Nearly a Posting Virtuoso

A couple of things:

for (i = 0; i < n; i++) << ; >>   // This section of the code is meant to determine 
                               // whether the values in the array are odd or even.
 
//remove the above semi-colon from the for loop 

    oddcount = 0;
    evencount = 0;[B]}[/B]

Don't put closing braces on the ends of the line of code. Closing braces go ONLY directly underneath (in the same column), as the opening brace OR the first letter of the line of code that they are part of:

for(......) {
  //other code here
}
//or

for(......)
{
   //other code here
}
Adak 419 Nearly a Posting Virtuoso

Ok, some touch up needed for your function:

Note that I sorted the strings in my example, because strings are harder for new C coder's to sort than numbers. Numbers compare directly, but strings have to be compared using strcmp() function.

void sortIntArray(StudFile sRec[], int num)
{
	int i, j, temp;
	int index[CLASS];

	StudFile gpa[CLASS] = {5.50, 2.22, 3.33, 4.44, 9.99, 6.66, 7.77, 8.88, 1.11};
	for (i = 0; i < CLASS; i++)
		index[i] = i;

/* the above for loop, initalizes the index[] array. It is NOT a part of the sort code, so you've left off the outer loop of the sorting code.
*/
        for(i=0;i<CLASS;i++) {
	for (j = i + 1; j < CLASS; j++) {

/* use strcmp() when you have strings to be compared - not for numbers */
             if(gpa[index[i]].studentGPA > gpa[index[j]].studentGPA) {
               //if(strcmp(gpa[index[i]].studentGPA, gpa[index[j]].studentGPA) > 0) {
		temp = index[i];
		index[i] = index[j];
		index[j] = temp;
	     }
	}
      }

      for(i = 0; i < CLASS; i++)
	 printf("%s \n", gpa[index[i]].studentGPA);
}

More like that.

Adak 419 Nearly a Posting Virtuoso

You're quite welcome.

Adak 419 Nearly a Posting Virtuoso

Needs a bit of touch up:

Basically this is the code but its not displaying my array just some random numbers.

Let's use MAX of 10, so you don't have to enter lots of numbers yet ;)

# include <stdio.h>
# define MAX 10
int main(void)
{
    int array[MAX],i,n;
    /* your array size is already set at MAX integers (0 through MAX-1) */
    //printf("\n Enter Array Size: ",MAX);
      
    for(i = 0; i < MAX; i++)
    {
       printf("\n Enter %d value: ",i+1); 
       scanf("%d", &array[i]);
    }
    //now print out the array
    putchar('\n');
    for(i = 0; i < MAX; i++)
    {
       printf("%3d  ",array[i]); 
    }
    getch();
    return 0;
}

By convention return 0 means run was normal. Anything else may be an error.

Adak 419 Nearly a Posting Virtuoso

The best way to sort structs, is to NOT sort the structs. ;) Sort an index array of simple int's, instead.

This is an example of "sorting" by the index. No data is moved in the process (the original order is retained). All the data can be written or displayed, in sorted order.

/* A small example of sorting through an index 
on an array of structs. The key is a string array member

status: ok 
*/

#include <stdio.h>

#define NumItems 4
#define StringLen 30

typedef struct {  //a simple struct with a string member
  char fname[30];
}name;           //and it's name is "name"

int main() {

   int i, j, temp; 

   //thanks, I'll take 4 of each:
   int Index[NumItems];
   name names[NumItems] = { {"Denise"},{"Barbara"},{"Abbey"},{"Cynthia"} };

   //initialize the index array
   for(i = 0; i < NumItems; i++)
      Index[i] = i;

   //now do a simple sort, using the initialized index array 

   for(i = 0; i < NumItems - 1; i++)  {
      for(j = i + 1; j < NumItems; j++)  {
         //only strcmp() compares strings! ;)
         if(strcmp(names[Index[i]].fname, names[Index[j]].fname) > 0) {
            //string i > string j, so it's out of sorted order
            temp = Index[i];      
            Index[i] = Index[j];  //so swap the indeces
            Index[j] = temp;
         }
      }
   }

   //Now to see the sorted data, use the Index array 
   printf("\n\n\n char array struct member, sorted by the Index[] :\n\n");
   for(i = 0; i < NumItems; i++)  
      printf("%s \n", names[Index[i]].fname);

   printf("\n\n\n Original data:\n\n");
   //to see the unsorted data
   for(i = 0; i < …
Adak 419 Nearly a Posting Virtuoso

Get that mode, three ways:

#include <stdio.h>
#define MAX 13

int main() {
  int i, j, mode1=0, count=0; 
  int digits[MAX]={20,20,20,14,13,8,8,8,1,1,1,1,1};
  int aux[100]={0};
  for(i=0;i<MAX;i++) {
     j=1;
     while(digits[i]==digits[i+j]) {
       ++j;
     }
     if(j>count) {
       mode1=digits[i];
       count=j;
     }
     i+=j-1;
  }
  printf("\n\nMode is: %d, found %d times", mode1, count);
 
  for(i=0, count=0;i<MAX;i++) {
    aux[digits[i]]++;
    if(aux[digits[i]] > count) {
      count = aux[digits[i]];
      mode1 = digits[i];
    }
  }
  printf("\nMode is: %d, found %d times\n", mode1, count);

  count=0;
  for(i=0, j=1;i<MAX;i++) {
    if(digits[i] == digits[i+1])
      ++j;

    if (digits[i] != digits[i+1] && j > count) {
      count = j;
      mode1 = digits[i];
      j = 1;
    }

    if (digits[i] != digits[i+1])
      j = 1;
  }
  printf("Mode is: %d, found %d times\n", mode1, count);	

  printf("\n\n\t\t\t     press enter when ready");

  (void) getchar(); 
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

Can line 15 be removed?

You get an A+ -- well done! ;)

Adak 419 Nearly a Posting Virtuoso

Thanks for this thread - I love it! ;)

Intuitively, you sense that there's a better way (and right you are), but can you find it (and using just the array and indeces)?

There is a relationship between i and j that is missing - but what could it be??
(i is playing dumb)

And then the question, do you need j at all?

Nope. ;)

This is too much fun to post up an answer right away - have fun with it. If no luck, I'll post back.

Note that your chaotic indentation doesn't hurt the clarity in this instance, but it's an excellent work habit to make it consistent. Subordinate lines of code should be indented, and indented a consistent amount of spaces.

Adak 419 Nearly a Posting Virtuoso

Greater than 0, not less than:

while ((n = fread(buffer,1,sizeof buffer, original_pointer)) < 0)
moroccanplaya commented: explains stuff verywell, and he is one clever guy +1
Adak 419 Nearly a Posting Virtuoso

Go through the array twice:

First time, count the number of times each letter appears. That's easily done using logic like this:

for each row
  for each columm
    ascii[this letter's ascii value]++, coded like:
    ascii[myLetter]++;
  end for
end for

(a 256 element array of type int, will do nicely for ascii[].)

Now when complete, go through the ascii[] array, and find the largest values(s), and assign them to your maxLetter1, maxLetter2, etc., variables.

Then go back through your array, and mark out the letter which equal maxLetter1, or maxLetter1 and maxLetter2, etc.


Sounds like it would take a long time, but it doesn't because the small array easily fits in cache memory -- Zoom! ;)

Adak 419 Nearly a Posting Virtuoso

Watch out!

The obvious patterns here are looking to bite you! ;)

You need to put some effort into this. We don't serve as homework bwitch's. We help people who are willing to show some real effort.

Adak 419 Nearly a Posting Virtuoso

You try to enter float type data, into integer variables -- that won't work.

Change your data type to float or double, for everything that handles anything with a decimal point, and your computations should improve a lot. ;)

A big hint for troubleshooting programs like this:

You have a LOT of data to be input for each run of the program. That's a real slow-down, when you need to run the program several times, to fix bugs that remain.

To speed it up HUGELY, just // the left side of the scanf() lines of code, and add an assignment line with a typical value, instead. Not:

scanf("%f", &someFloatvariable);

//but

//scanf("%f", &someFloatvariable);
someFloatVariable = 88.15;

Now you can troubleshoot MUCH faster. ;)

You'll need to cut out the assignment line of code, later on, but in the meantime, you can really scoot on your troubleshooting.

Adak 419 Nearly a Posting Virtuoso

In the future, ALWAYS use the code tags (icons are in the editing window of the forum). Just paste your code between the supplied [CODE ] [/CODE ] tags. (You get a pair of code tags by clicking on the [CODE ] icon.)

This is your program, formatted, and using code tags:

#include<stdio.h>

main()
{
    int prelim,midterm,semifinals,finals;
    int quizzes,assignments,project,attendance;
    int exam,classstanding,total;
    int sum,product,compute,grade;
    clrscr();
    printf("\n\n\n\t\t\t BSU GRADING SYSTEM");
    printf("\n\n\n\t\t\t by ");
    printf("\n\n\n\t\t\t THERESA DENISE MATALA");
    getch();
    clrscr();
    printf("\t\t\t\t EXAM ");
    printf("\n\n PRELIM: ");
    scanf("%d",&prelim);
    printf("\nMIDTERM: ");
    scanf("%d",&midterm);
    printf("\nSEMI FINALS: ");
    scanf("%d",&semifinals);
    printf("\nFINALS: ");
    scanf("%d",&finals);
    getch();
    clrscr();
    printf("\t\t\t\t CLASS STANDING ");
    printf("\n\nQUIZZES: ");
    scanf("%d",&quizzes);
    printf("\nASSIGNMENTS: ");
    scanf("%d",&assignments);
    printf("\nPROJECT: ");
    scanf("%d",&project);
    printf("\nATTENDANCE: ");
    scanf("%d",&attendance);
    getch();
    clrscr();
    printf("\n\n\n\n\n\n\n\n COMPUTE ");
    getch();
    clrscr();
    printf(" COMPUTATION ");
    printf("\nEXAM%: ");
    scanf("%d",&exam);
    prelim=grade*0.12;
    midterm=grade*0.12;
    semifinals=grade*0.12;
    finals=grade*0.24;
    exam=prelim+midterm+semifinals+finals;
    compute;
    printf("\nCLASS STANDING%: ");
    scanf("%d",&classstanding);
    quizzes=grade*.5;
    assignments=grade*.15;
    project=grade*.15;
    attendance=grade*.5;
    compute;
    printf("\nTOTAL: ");
    scanf("%d",&total);
    total=exam+classstanding;
    getch();
}

Don't you want to use loops to have the data entered into the program? Or is each student going to have just one quiz mark, one test mark, etc.?

Adak 419 Nearly a Posting Virtuoso

This is not a "do my homework for me" forum.

Either show your effort to solve this assignment, or resign yourself to disappointment.

Adak 419 Nearly a Posting Virtuoso

@Adak

Why are you recommending

#define LONG 8
#define INT 4
#define SHORT 2

instead of the compile time sizeof operator?

I wanted him to use the sizeof operator to get these numbers right. THEN put them into defines to simplify his thinking on this assignment.

When I first thought about this, I wrote out some code idea's that used sizeof(), but then I thought "Let's Arch Linux" this bad boy assignment, and simplify/clarify it a bit more.

I'm unsure if it was helpful or not. In general, I like and recommend using the built in operator's for a program, but sometimes a few simple defines are really helpful.

Adak 419 Nearly a Posting Virtuoso

hello again
i got an assignment i thought i understand it but the every time i read it i understand it differently. my teacher won't explain the exercise.
here is the exercise
[IMG]http://img42.imageshack.us/img42/8331/37255827.png[/IMG]
he also gave an input output example located here
http://rapidshare.com/files/434579925/sorted.zip
i'v learned using shmat & shmget and using semaphore.
i have a few questions
1)if the size given to me is 8 what should i do? am i suppose to use long long?
2)if the size is given to me is 1 one can i use reguar int?
3)i want to do bubblesort and before the swap to lock the semaphore am i right?
4)i started writing 4 cases how does it look

if ((shmid = shmget(IPC_PRIVATE, st.st_size, 0600 | IPC_CREAT)) < 0) {
		perror("shmget error");
		exit(1);
	}
	if (num_of_bit != 8) {
		if (argv[4] == "signed") {
			if ((share1 = (int*) shmat(shmid, NULL, 0)) == (int*) -1) {
				perror("shmat error");
				exit(1);
			}
			kind = 1;
		} else {
			if ((share2 = (unsigned int*) shmat(shmid, NULL, 0))
					== (unsigned int*) -1) {
				perror("shmat error");
				exit(1);
			}
			kind = 2;
		}
	} else {
		if (argv[4] == "signed") {
			if ((share3 = (long long int*) shmat(shmid, NULL, 0))
					== (long long int*) -1) {
				perror("shmat error");
				exit(1);
			}
			kind = 3;
		} else {
			if ((share4 = (long long unsigned int*) shmat(shmid, NULL, 0))
					== (long long unsigned int*) -1) {
				perror("shmat error");
				exit(1); …
Adak 419 Nearly a Posting Virtuoso

What I like to do is call menu() function from main. Menu() is just a BIG while(1) loop, with code to exit when the user requests it.

Inside the while loop, it prints the header or banner, the menu options, and has a big switch (choice) block of code, to handle all responses.

When the user wants to quit, menu() just returns to main(), which may have as little as two lines in it:

int main(void) {
  menu();
  return 0;
}
Adak 419 Nearly a Posting Virtuoso

Do you want to use the %x or %X (hexadecimal) format in printf()?

printf("\n%x/%x \n",numerator, denominator); //or X for upper case letters