Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,912 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,549 people online right now. Registration is fast and FREE... Join Now!




files in a function.. hmmm

 
Reply to this topicStart new topic

files in a function.. hmmm

zattara13
10 May, 2008 - 10:25 AM
Post #1

New D.I.C Head
*

Joined: 27 Mar, 2008
Posts: 26

i got this last function not working... giving me error C2087 : 'array2' : missing subscript in line 59, last function that is... anyone know what the problem might be? 10x

CODE


#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>

#define SIZE 100

double random_no ();
double arcsine (double value);
int file ();


int main (void)
{
    int        i, j, a ,b;
    int        array1[101][181] = {0};
    float    rno;

    srand (time(NULL));

    

    for (i=0; i<10000; i++)
    {
        rno = random_no();
        a = 51-(50*(rno));
        b = 91 + arcsine (rno);
        array1[a][b] = 1;
    }

    for (i=0; i<101; i++)
    {
        for (j=0; j<181; j++)
        {
            file (array1[i][j]);
            printf ("%d", array1[i][j] );
        }
    }

    return (0);
}

double random_no ()
{
    return (((double)rand() / (RAND_MAX) * 2 ) -1);
}

double arcsine (double value)
{
        return ((asin(value))*360 / 6.283185);
}

int file (int array2[][])
{
    FILE *cfPtr;
    int i,j;

    (cfPtr = fopen ("question 1.dat", "w"));
    
        while (!feof(cfPtr))
        {
            fprintf (cfPtr, "%d", array2 [i][j]);
        }

    fclose (cfPtr);

    return (array2[i][j]);
}


User is offlineProfile CardPM
+Quote Post

Mike007
RE: Files In A Function.. Hmmm
10 May, 2008 - 12:14 PM
Post #2

D.I.C Head
Group Icon

Joined: 30 Aug, 2007
Posts: 205


Dream Kudos: 75
My Contributions
cpp
(cfPtr = fopen ("question 1.dat", "w"));


This line right here is your problem, well one of them, you probalby wanted to make that an if statement. Other problems are that you don't really change the value of i and j which is set to nothing (or garbage in c++ case).

Well you're code seems to need alot more planning, next time plan before you code! Because i think that even you can't understand what it is you were trying to do there, or how you planned on doing it.

Good luck.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:49AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month