Adak 419 Nearly a Posting Virtuoso

The specifics depends on how your program is structured, which you haven't posted, or described in the detail that's needed.

Post your program's code, and give us an example of what you want to do:

*input you have
*processing you want
*output you want

Please, not just a description - but an actual example. Normal language is poor at communicating these kinds of details. Any math is fine as well, of course.

Adak 419 Nearly a Posting Virtuoso
mkdir   Creates a directory.


 Syntax:
   int mkdir(const char *path);

 Prototype in:
 dir.h

 Remarks:
mkdir creates a new directory from the given
path name path.

 Return Value:
mkdir returns the value 0 if the new directory
was created.

On error, a value of -1 is returned, and the
global variable errno is set to one of the
following values:

   Setting ³ Description
  
   EACCES  ³ Permission denied
   ENOENT  ³ No such file or directory

 Portability:
mkdir is available on UNIX System V, though it
takes an additional file-mode parameter.

 See Also:
  chdir    getcurdir    getcwd    rmdir

 Example:
 #include <stdio.h>
 #include <conio.h>
 #include <process.h>
 #include <dir.h>

 int main(void)
 {
   int status;

    clrscr();
    status = mkdir("asdfjklm");
    (!status) ? (printf("Directory created\n")) :
                (printf("Unable to create directory\n"));

    getch();
    system("dir");
    getch();

    status = rmdir("asdfjklm");
    (!status) ? (printf("Directory deleted\n")) :
                (perror("Unable to delete directory"));

    return 0;
 }
Adak 419 Nearly a Posting Virtuoso

You haven't yet met Mr. strcmp() I presume? ;)

Adak 419 Nearly a Posting Virtuoso

Now, we're getting somewhere, at last.

First, you know the arrays have to be local, so remove them from above main() and declare them inside main().

Second, the name of the array is a constant pointer (almost!) to the base of the array, so let's make the call to the function, with just the two names of the pointer.

Third, the receiving function will take these two arrays as pointers to the struct array, which you have already typedef'ed, so this kind of a function parameter list, should be OK:

void fun (POINT *pointar, CIRCLE *circlear);

If the 3 is something that might be changed later, let's do a #define MAX 3 statement, (note no = char and no semi-colon either), right below the #include file list. In fact, it's such a darn good idea, let's do this define, anyway. It's a great habit to get into.

Then see what errors you're getting, and please re-post the program so we aren't talking about what was - only what is.

And you can please lose the void main() -- that is not C.

Adak 419 Nearly a Posting Virtuoso

I'm not sure what you're trying to do here, are you messing with us or what?

You need three things for a function call:

1) The call - we've got that
2) The function prototype - we've got that
3) The function itself - and we don't have that

You have declared pointar and circlear as global arrays of three structs. That means you don't need to pass them to any function, and it's an error to do so (your compiler may not mind, but the result will be nothing you wanted will happen).

So I'm really confused what you're trying to do here - post what you want, and post the whole friggin' program (a working example is fine), and let's quit the hide and seek with the code, game.

You have to be specific - do you want the pointar and circlear arrays global or local, etc.

Adak 419 Nearly a Posting Virtuoso

In this code:

typedef struct point CIRCLE;

did you mean:

typedef struct circle CIRCLE;

??
;) ;)
Funny, but I've done that kind of stuff many times, myself.

In C, it's always int main, never void main, and with a return 0 at the end. You should be getting a warning or error about that.

Adak 419 Nearly a Posting Virtuoso

Hop in your time machine. Set the date for about 1999. Look into WindowsME, and earlier versions of Windows. After that, the NT kernel came into use from the server line, and that pretty much ended these kinds of shenanigans.

Adak 419 Nearly a Posting Virtuoso

Add ctype.h for isalpha and tolower.

All your functions should have prototypes above main(). Preferably, right below the include files list and any defines you have.

That takes care of most of your errors. May raise some other errors, of course.

Make these changes, and re-compile and see what you have then. Also, repost your code so if we study it, we won't be looking at obsolete code.

It may not make a difference right now, to you, but most of us will receive a warning or an error for void main(void).

That is not standard C, and hasn't been standard C since J.C. was a Corporal. It's always int main(void), never void main(void). On the end of main, it's always return 0.

Yes, I know books leave it out, oftentimes - but that's wrong. It will cause some problems, down the line, and make warnings or errors, now.

Adak 419 Nearly a Posting Virtuoso

What are your include files for this program? You left them off.

Adak 419 Nearly a Posting Virtuoso

You put in a string of words as ONE string. The strcat() I don't believe was necessary or desirable. But you're expecting an end of string char, for every word, and there will not be one for every word. There is just one (originally) for the entire string of words.

Change your logic to look for the space, and then if your letters have matched since the last space was reached, you have a matching word.

Adak 419 Nearly a Posting Virtuoso

Thanks Adak,
The angle is given in radians and the tolerance is (+/-0.05 rad). I am using it for the FFT Function, I posted in my other post about the malloc function, and I am using it for processor on a development board.
How would I fill the array though? It would be really long to fill it manually, unless of course I use the sin() function once to fill it. My question is then, how would I access it? My angle value will be some decimal number, how do I link it to the closest angle given in the table? Would I need to round the angle to the nearest angle provided in the array?
Thanks

You might load a look up table from a file, or have it calculated when the program first starts up, but probably the most common way is to simply assign the table with values.

No, I've never seen a look up table filled manually -- you're cracking me up here ;)
It could happen, odd though it sounds. Wouldn't advise it though.

This is an example of several look up tables, from a Sudoku program (it's not mine):

/****************************************************************\
**                                                              **
**  BB_Sudoku  Bit Based Sudoku Solver                          **
**                                                              **
**             Copyright (c) 2008, Brian Turner                 **
**             All rights reserved                              **
**                                                              **
**  BB_Sudoku_Tables.h : This file contains the various tables  **
**    used by the solver:                                       **
**                                                              **
**  General purpose tables: …
Adak 419 Nearly a Posting Virtuoso

You could google Microsoft Visual C/C++ Express (it's free), and also, download the video tutorial that shows how to use it (also free). By default, programs with the dot cpp extension are handled by the C++ compiler, and files with the dot c extension, are handled by the C compiler. The IDE for both, is the same.

Another good choice is the Pelles C program (also free). They have a fine IDE also, be sure to join their forum to answer your questions on using the Pelles C IDE (Integrated Development Environment), if you have any.

Adak 419 Nearly a Posting Virtuoso

You don't seem to have the malloc or the passing array part of the logic, just right. Post enough of the code that we can get an example that is meaningful to correct for you.

Those errors have to be studied - post them up with your expanded example. Minimum to show is the array declaration, and the function call, and the function that is being called.

The above snippets aren't enough info (for me at least).

Adak 419 Nearly a Posting Virtuoso

Without seeing the code, it's hard to make decent suggestions on how to optimize it. Can you post it, and be more detailed about the +/- error that is acceptable?

I'm not clear about what has you stumped either, about creating a look up table. It's a 2D array (frequently). Your program can get precomputed/preloaded values by just referring to the right array element's value. Nothing esoteric, really.

Imagine for a moment that you are in a library. Everything you need for reference, is in the library. When you need a piece of info, you can go to the card catalog, and then to the right row of shelves, and eventually locate the book with the right info -- OR you could just look at a little pad next to you at the table, with the info you need. That's a look up table.

Adak 419 Nearly a Posting Virtuoso

The key is in the file names themselves: data-01.txt, data-02.txt... to data-20.txt.

Use a char array fname[MAX] to construct each of your filenames:

char fname[12] = {"data-"}; //leave for for the end of string char: '\0'
char num[3] = {"00";
char ext[5][".txt"};
int fnumber;

then use a for loop, and strcat() to add on the next number: 
for fnumber = 1 to 20
  num = itoa(fnumber);
  printf num
  if(num[0] == 0) {
    num[0] = num[1];
    num[1] = '\0'; //end of string char
  end if
  strcat num onto the end of fname
  strcat ext onto the end of fname
  print fname to check it's doing it right
  open the file and process as normal here
end for

This approach works, but the above may not be as polished as I'd like. Post back if that pseudo code doesn't spark any flashes of light for you.

Adak 419 Nearly a Posting Virtuoso

Turn it over 90 degrees, and see the columns as rows, and the rows as column. memcpy helps a lot. ;)

#include <stdio.h>
#define R 4
#define C 5

int main() {
  int i,j, r, c,n; 
  int grid[R][C]={
  {0,0,3,4,5},
  {0,3,2,1,6},
  {0,0,0,2,0},
  {6,2,0,3,1},
  };
  int temp[R];

  printf("\n\n\n");
  for(r=0;r<R;r++) {
    for(c=0;c<C;c++) {
      printf("%d ", grid[r][c]);
    }
    putchar('\n');
  }
  //start sorting
  printf("\n\n\n");
  for(c=0;c<C;c++) {
    for(r=0;r<R;r++) {
      if(grid[r][c] < grid[r+1][c]) {
        memcpy(temp, grid[r], C);
        memcpy(grid[r], grid[r+1], C);
        memcpy(grid[r+1], temp, C);

      }
    }
  }

  for(r=0;r<R;r++) {
    for(c=0;c<C;c++) {
      printf("%d ", grid[r][c]);
    }
    putchar('\n');
  }
  

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

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

This is what I've used for Shell sort:

//Shell sort
void shellsort(int A[]) {
  int i, j, gap, temp;
  for(gap = MAX/2; gap > 0; gap /= 2) {
    for(i = gap; i < MAX; i++) {
      for(j = i - gap; j >= 0; j -= gap) {
        if(A[j] > A[j + gap]) {
	  temp = A[j];
	  A[j] = A[j + gap];
          A[j + gap] = temp;
        }
      }
    }
  }
Adak 419 Nearly a Posting Virtuoso

Yes, exactly,

however: ;)

It's a bit complicated, because in Linux/Unix/and all binary files, '\n' is the newline, and that's that - simple.

In text mode however, *sometimes* you'll see a newline as a TWO char combination: CR (carriage return), and LF (line feed). So if you see an obvious problem with '\n' somehow being ascii 10 followed next by ascii 13, then you'll know why that is, and can move to handle it.

That happens because text file handlers "expand" a newline, into CR/LF combo's, which usually your C program will handle as one char OK, but always -- well, no.

Always is such a long time, eh? ;)

Adak 419 Nearly a Posting Virtuoso

First - that's not a program you posted, or a snippet of code that will run.

Second - you NEED to use CODE tags. Click on the icon in the forum's editor and paste your code, between the tags it provides you.

Third - you didn't give size a value, but you use it to stop the for loop. ??

Fourth - [B]Welcome to the forum, Bkoper![/B] ;)[CODE ] icon in the forum's editor and paste your code, between the tags it provides you.

Third - you didn't give size a value, but you use it to stop the for loop. ??

Fourth - Welcome to the forum, Bkoper! ;)

Adak 419 Nearly a Posting Virtuoso

When you scanf() for a number, whitespace char's are passed over. That's one of the advantages of getting input as a stream of char's, btw.

What you can do is change your fscanf() from %d to %d%c, format. Assign a char to %c, like normal &ch.

Now %c will put all the spaces AND the newline (when it reaches the end of the row), into that ch variable, and you can test it, and use that, for your end of row test

Adak 419 Nearly a Posting Virtuoso

You can always change a while loop into a for loop, but you need to include the right check for a stop condition - which you don't show at all.

Adak 419 Nearly a Posting Virtuoso

If you had a discount array, where every day was represented by the number of the row, and every column represented the hour of the day:

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0            1        2        3

Then each element could hold the discount applicable to that day and time.

Sunday (row 0): 0 (midnight) 1 (0100) 2 (0200) 3 (0300), etc.
Monday (row 1): 0 0.10 (10%) 1  0.08  2  0.05  3 0.04  , etc.

The key is the tie between day of the week and the row number, and hour of the day (after midnight) and the column number.

And Welcome to the forum, Steve! ;)

Adak 419 Nearly a Posting Virtuoso

In pseudo code, for six numbers, this will do it. Change define C to whatever number of numbers per row you need.

include stdio.h

define R 2
define C 6

begin main() 
  declare:
  =========
  ints i,j, r,c, ok 
  char ch
  int a[R][C]  //R=Rows, C=Columns
  FILE * fp
  //end declarations
  //begin processing
  print("\n\n")
  fp = fopen("input.txt", "r")
  if(fp==NULL) 
    printf("\nError opening file\n")
    return 1
  end if

  set r and c to 0
  set ok to 1
  while((ok=fscanf(fp, "%d%*c", &a[r][c])) > 0) {
    if(ok less than 1)
      break
    print("%d ", a[r][c])
    ++c
    if(c equals C)
      set c to 0
      ++r
      putchar('\n')
    end if
  end while loop
  print("\n\n\n")
  fclose(fp)
  printf("\n\n\t\t\t     press enter when ready");

  (void) getchar() 
  return 0
end program

If input text has this input:
1 2 3 4 5 6
6 5 4 3 2 1

That is what the program prints up, and assigns to array a[r][c].

I left this in semi-pseudo code, because I see that you want to learn, and there's no better way to learn, imo, than taking pseudo code that works, and making it into a program.

Adak 419 Nearly a Posting Virtuoso

You have to declare your variables, before you can use them. Generally, it's best to declare them, right at the top of the function they are used in.

Adak 419 Nearly a Posting Virtuoso

Are there always 6 numbers in a line, or are there sometimes less or more than six numbers?

Adak 419 Nearly a Posting Virtuoso

So make it describe what it's doing, the way you want it. It's 4 a.m. here, and I wanted something more descriptive. ;)

Adak 419 Nearly a Posting Virtuoso

Getline is a function to make it a bit easier to get a line of text. In some languages, it's standard, but not in C. fgets() is not as simple as gets() (which is absolutely simple as pie), but gets() is NOT safe - all the hackers know how to use it's weakness to create havoc.

Like most things that you want to do, there's more than one way to do this. You want to use fscanf() for this?

Is the input.txt numbers, formatted like this?
1 2 3 4 5 6

(six numbers, each separated from the next by one space)

Adak 419 Nearly a Posting Virtuoso

* ALWAYS * use code tags on code forums. Forum software turns your code into html junk, otherwise - very hard to study.

#include<stdio.h>
int main (){
  int counter;
  int x;
  int product;

  counter=0;
  x=1;
  product=1;

  while (counter<5){
    counter++; //this is C!
    product*=x;
    printf("x:%d *= product is: %d\n",x, product);
    x+=2;

  }

  printf("Product>%d",product);
  (void) getchar();
  return 0;
}

See what that adds up to - I haven't run this.

Adak 419 Nearly a Posting Virtuoso

If I print out int's, then the file will have int's in it. When you print out strings of char's, then the file will have char's in it. EVEN if the char is a digit, it will still be a char digit, and not a true int.

The beauty of what the code I posted it, it doesn't matter whether the original data was a char string with digits, or real int's.

It takes them all in as char's, and THEN it transfers them into true int's.

Works either way. ;)

Adak 419 Nearly a Posting Virtuoso

The code you posted, is writing out strings of char's, not ints:

fprintf(ExistingFile, "1 0 0 1 1\n");

See those double quotation marks around your string of digits? That's a sure sign it's a string, in C.

Adak 419 Nearly a Posting Virtuoso

This is one way:

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

int main() {
  int i,j; 
  char a[]={"1 22 33 444 5555 5 4 3 2 1"};
  int n[10];
  
  for(i=0,j=0;i<10;i++) {
    n[i] = atoi(a+j);
    while(a[++j]!=' ');
    printf("\n %d: %d", i, n[i]);
  }
  printf("\n\n\t\t\t     press enter when ready");

  (void) getchar(); 
  return 0;
}

Don't expect a safety net with atoi(). You won't get anything except a 0 on error.

Check your compiler and see if it has the safer strtoi() (string to int).

I've had good weather and fair winds with atoi(), personally.

Adak 419 Nearly a Posting Virtuoso

You can do this with just one pair of nested loops, but I like using two to simplify it.

The first pair of nested loops fills the char array a[][] with the correct values. The second pair of nested loops, prints them out.


Clear out the array, to just spaces:

char a[R][C];

//zero it out:
for(r=0;r<R;r++) 
  for(c=0;c<C;c++)
    a[r][c] = ' ';  //a space

Now the real loops in pseudo code:

for each col 
  for each row  //like turning the array 90 degrees counter clockwise
    if row < value in your occurrences array for col's value
      a[row][col] = '|'
    else if row == value in your occurrences arrary
      a[row][col = '^'
  end of for each row
end of for each col     

Now you're ready to print, but it has to be from the top down, so it will display with the higher values being higher up on the screen.

for r=R; r> -1; r--
  for c=0; c < C;c++ //still going upward on c, so it reads left to right
    print a[r][c];
  end of for c=0...
  putchar('\n'); //end of a row
end of for r=R...

And there you go. Add your footer lines, and anything you need along the vertical on the far left or right hand side, for the scale.

;)

Adak 419 Nearly a Posting Virtuoso

Check out "Brainphuck" language, on Wikipedia. (with an 'f') ;)

It messes with you, but it's not English, for sure. ;) They mention others, as well.

Adak 419 Nearly a Posting Virtuoso

Is this for an assignment, or for real cryptographic use?

It's very easy to do a simple encryption scheme yourself for an assignment, but it's quite another thing to devise a scheme to make it secure from attack. For real work, it's best to use a proven library - no doubt about it. For a one time scheme, it's hard to beat the One Time Pad method (go to Wiki for more info). It's cumbersome, but for one time, quite doable.

This is a PDF on "lightweight" stream ciphers - quite enlightening. Wikipedia has a whole portal on Cryptology btw, which covers several popular ciphers.

http://biblion.epfl.ch/EPFL/theses/2008/4040/EPFL_TH4040.pdf
(multi-lingual but plenty of English)

The biggest mistakes people make in this regard, is thinking that some cipher is "unbreakable", or that a clever untested cipher is secure. Cryptologists have come up with amazingly sophisticated ways to decode messages.

Of course, it can't go unmentioned that no cryptographic system is secure, if the humans running it are in any way, careless in how they handle the details thereof.

Adak 419 Nearly a Posting Virtuoso

You need an outer "overall" loop (usually a for loop, let's say)

for(each number) {
   j=1;
   while(array[i] == array[i+j] { //because they're *sorted*
      ++j;
   }
   if(j > maxRepeats)
     mode = array[i];
}

That's to get you started, you may have one off errors in it -- it's very late here.

The key thing is, since the numbers are sorted, the repeating numbers, will be right next to each other. So a while or do while loop, is an intuitive way to do it.

Adak 419 Nearly a Posting Virtuoso

The easiest way to do this might be to use an array of structs, where the struct was prototyped right below the include files, with members like int ID; char name[50]; etc.

Then in main() create an array of those structs with struct student students[50] (for say, 50 students). Each field can be accessed with the dot operator -
students[0].ID, or students[2].name, for instance.

Wikipedia has an extensive page on all those kinds of sorts, and Google is always your friend, as well.

I hope you're not waiting for someone to do it for you - that (almost) never happens on this forum. We help you - but don't do it for you.

Post up your code and tell us what has you stumped. But don't wait for someone to do this for you, on this forum.

I couldn't get your page to display, btw. Generally always better to post it, directly. Linked stuff tends to be easily ignored.

Cheers! ;)

Adak 419 Nearly a Posting Virtuoso

For your sorting functions, look at Wikipedia and search for Sorting algorithms.

In general, if the function just goes through the data, one time, that would be your 0(n), complexity. Since obviously the complexity is directly a product of the number of items being handled, and nothing else.

If it uses nested two nested loops, you have something more - maybe up to (n*n).

If it's nutty like Bogo sort, then it's still worse, of course. ;)

The best general sorters like Quicksort, are n(log n), all others (like your selections sort), are worse, (have higher big O values).

While you're over at Wikipedia, give a read on Big O (oh, not zero), notation. Then try and figure out what's what in your assignment.

When you post code, put tags around it [/CODE ]. Just highlight your code, and click on the code tag icon in the editing window.[CODE ] tags around it [/CODE ]. Just highlight your code, and click on the code tag icon in the editing window.

Adak 419 Nearly a Posting Virtuoso

You need to first show us that you are working on this problem.

So, what have you done to try to program this?

Generally, posts with no attempt of code being posted, are skipped over. Post up what you've done, and be specific about what has you stumped.

We want to help, but not be your homework biitch.

Adak 419 Nearly a Posting Virtuoso

Add:

#include <limits.h>

Either use a

#define SIZE 12

macro, or get size this way:
size=sizeof(a)/sizeof(a[0];

You'll need that size of the array, I'll show you why.


This is NOT refined code - I believe this is best done recursively, but recursion
is hard to follow, without some experience with it.

for(i=0;i<size;i++) {
  //your main loop
  j=i+1;
  n=a[i];
  compress=0;
  while(a[j]==n && j<size) {
    compress++;
    a[j] = INT_MIN;
    ++j;
  }
  /*if you have a compression here
  increment i and set a[i] to compress+1
  and you need to shuffle the digits, down
  */
     //meet shuffle time ;)
    for(j=i+1;j<size;j++) {
      if(a[j] == INT_MIN) {  //found an element that needs to be overwritten 
        --size;              //reducing the effective size of the array by 1   
        for(k=j;k<size;k++) { //copying down the digits
          a[k] = a[k+1];
        }
        --j;                  //yup, tinkering
          
         //printf("\n Size = %d\n", size);
         //for(m=0;m<size;m++)
           //printf("a[%d]=%d ", m, a[m]);
      }
    }
  }//end if 

}//end for

Work with something along those lines, Joey.

Joey_Brown commented: gr8 guy !! +1
Adak 419 Nearly a Posting Virtuoso

Be definition, you don't need code to add zeroes to the array - you are compressing it, not adding to it's length.

Think along these lines:

for i=0, j=0; i< SIZE of array;
  assign a[j] to num1
  set compress = 0
  while j < SIZE
    if a[j] == num1
      ++compress
  if compress > 0
    a[i+1] = compress
   for(k=i to j)
    mark each array element with a unique value (not zero)  
   (maybe INT_MIN?)  
  j+= compress
end for loop

ais where the compressed digit indicator goes. a[j] is where the next digit to be looked at, is located.

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

void show(int (*)[3],int,int);

int main()
{
  int a[3][3]={1,2,3,
	       4,5,6,
	       7,8,9};

/* I would prefer the explicit:
  int a[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
note the doubled braces
*/
                

  show(a,3,3);
  return(0);
}
void show(int (*p)[3],int row,int col)
/*I would use:
void show(int p[3][3]) 
using the call 
show(a);

Which emphasizes at a glance (to me anyway), that it's a true 2D array
that is being referred to, here.
*/

{
  int i,j;
  printf("\n\n\n");
  for(i=0;i<row;i++)
   {
     for(j=0;j<col;j++)
	printf("\t %d",p[i][j]);
     printf("\n");
   }
}

Is it right way??

Always test it with YOUR compiler and system. If it's always accurate - and you get no warnings (of note), or crashes, or errors in the output - then you can say "I didn't find any bugs, at all!" ;)

Because you can never prove that a program of any complexity, has no bugs. You can only prove that it had no bugs that were found, in your tests.

vinitmittal2008 commented: Detailed and Usefull Information +1
Adak 419 Nearly a Posting Virtuoso

Your spacing is a bit different than the spacing for the last calendar post, so I'll need to adjust that.

Let's see what you have for your spacing, ...

/* prints up a monthly calender

*/

#include<stdio.h>

int main() {
  int totalDays,day, i, r, c, firstDay;

  printf("\n\n\n");
  printf("Input Number of days in a month: ");
  //scanf("%d",&totalDays);
  //(void) getchar();
  totalDays=31;
  printf("Input the first day of the month: \n");
  //scanf("%d",&firstDay);
  //(void) getchar();
  firstDay=5;
  printf(" Su   M  Tu   W  Th   F  Sa\n");

  for(r=0,day=0;r<5;r++) {
    if(r==0) {
      for(c=0;c<7;c++) {
        //if(c==1 || c==3 || c==5)
         // putchar(' ');
        if(c<firstDay) 
          printf("    ");
        else
          printf(" %2d ", ++day);
      }
      putchar('\n');
    }
    for(c=0;c<7;c++) {
      if(++day>totalDays)
        break;
      //if(c==1||c==3 ||c==5)
       // putchar(' ');
      printf(" %2d ", day); 
    }
    printf("\n");
  } 
  printf("\n\n\t\t\t    press enter when ready");
  (void) getchar();
  return 0;
}

run this, and let me know how the spacing looks to you.

Adak 419 Nearly a Posting Virtuoso

All two player games follow a very similar pattern:

print introduction
print instructions if user requests them
initialize the cards, board, create any data structures needed
to play the game, etc. Set options, read from a data file,
all the "set up" stuff.

print up a menu asking user if they want to play

Start the "big game loop":

while player doesn't quit and game isn't over
  print the board
  print the move notes, if any
  get the user's input
  process the input with a step of game play
  switch players turn
end while

I don't know anything about Nokia D, but if you don't know how to program Tic-Tac-Toe type of a game, then don't try to program a much more difficult game. You'll just get frustrated and quit. The help that we can give you won't be enough, without substantial coding up, from you.

I'm suggesting this because you posted no code at all, in your first post in this thread. That suggests that you are unable to code any kind of game, at this time.

Why don't you download some Tic-Tac-Toe type of simple two person game codes, and study them. See what makes them tick, and how you could get started writing up a Nokia D type game, if that is your passion.

When you have that level of understanding, we can help you much more than today.

Adak 419 Nearly a Posting Virtuoso

Best idea for you would be to get all you can done, especially the parts that relate to the electronics. Direct your electronic questions to one of the electronic forums - (Google for that).

Come back here for any questions you need answered having to do with C. I have not seen any electronic questions answered on this forum.

C what I mean? ;)

Adak 419 Nearly a Posting Virtuoso

You're welcome. ;)

Adak 419 Nearly a Posting Virtuoso

Your code doesn't show any closure for the file you created. That can cause a problem.

Add:

fclose(ofp);

when your program is done writing data to the file. That will flush out any data that hasn't been written yet to the file, that is being held by a buffer.

My bet is that is your problem. Most hard drives are set up for buffered writing (for efficiency), and you haven't put much data into the file buffer, yet. Then you didn't close the file, so the data may not have been written out.

;)

Adak 419 Nearly a Posting Virtuoso

Well, two reasons:

1) he has an array, already, but no linked list. More efficient here, to just use what he has.


2) Does he know how to use a linked list? I don't know. My guess is no, he doesn't. If you don't know how to find the minimum value in an array, you probably don't know how to work with a linked list yet, either.

But it could be done with a linked list! ;)

Adak 419 Nearly a Posting Virtuoso

For printing the calendar for the month, you can use this pseudo code:

print your days of the week on a line with a couple spaces between each day

day equals 1
for row=0, and each row less than 5, increment row
   if row is 0
     for col=0 and each col less than 7, increment col
       if col less than firstNum
         print 4-5 spaces: "     "
       else
         print day 
   else
     for col=0 and each col less than 7, increment col
       increment day
       if day greater than daysInMonth
          break out   
       print field two digits wide, day + a space or two
     
     print newline '\n'
   end of else
 end of for

end of function

That will get you started

Adak 419 Nearly a Posting Virtuoso

@civirol02:

I just answered this question in your other calendar display thread.

Please, just one program per thread, or you'll wind up wasting a great deal of our time.

The calendar display problem is solved.

Adak 419 Nearly a Posting Virtuoso

The alignment for all rows is perfect, on my screen.

What input for total days and first day are you seeing this problem with?