User Profile

Collapse

Profile Sidebar

Collapse
fishwater00
fishwater00
Last Activity: Jul 9 '08, 09:18 PM
Joined: Jun 17 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • fishwater00
    replied to How to interpret this input problem?
    in C
    Thank you. I fix it.
    Code:
    char *buff
    ...
    See more | Go to post

    Leave a comment:


  • fishwater00
    replied to How to interpret this input problem?
    in C
    Thanks. it hsould be strncmp.

    Do I need to define "buff", if I donot define buff, error message shows "‘buff’ undeclared (first use in this function)". if I define "*buff" as int or float, it will shows the message like:

    warning: passing argument 1 of ‘fgets’ from incompatible pointer type
    warning: passing argument 2 of ‘mystrcmp’ from incompatible pointer type
    ...
    See more | Go to post

    Leave a comment:


  • fishwater00
    started a topic How to interpret this input problem?
    in C

    How to interpret this input problem?

    I need to read parameters from a file called "params", the following is part of codes which can read parameters from that file. But I am not totally understand. Hope anyone can give detailed answers. Thanks.

    In a file called "params.c"
    [code=c]
    #include "systems.h" /* it includes all .h codes I need */

    int mystrcmp(const char *tag, char *buff)
    {
    int l =...
    See more | Go to post

  • How can I pass value from whole array to sequential array?

    I do not know how to express the array I am going to work with, but some codes can describe them.

    If I define an array and a struct with member :
    [code=c]
    float velocity;
    MODEL.VELOCITY;
    [/code]
    VELOCITY in struct MODEL is also float.
    then I alocate memory for them;
    [code=c]
    velocity = malloc( NX*NY*NZ*sizeof (float); /* in 3D case, NX,NY,NZ are the length, here it is original...
    See more | Go to post

  • fishwater00
    replied to Segmentation fault--allocation error?
    in C
    Thanks. I already add * to it, but still have those problem. I think it is the allocation problem.

    I wonder if you or anyone can write some codes about allocation of arrays of struct. That would be great.

    Thank all in advance....
    See more | Go to post

    Leave a comment:


  • fishwater00
    replied to Segmentation fault--allocation error?
    in C
    Thank you. In my case, the struct include many different arrays, such velocity[k], wave1[k], wave2[k], wave3[k], derivatives1[k], derivatives2[k], and so on. every array almost need k=nx*ny*nz*size of(float) memory. But, like you said, I do not know how much memory I need to reserve, and I try to allocate dynamic memory. In other word, In domain[0], domain[1],... each domain[i] includes velocity[k], wave1[k], wave2[k],... All I did is in 3D case....
    See more | Go to post

    Leave a comment:


  • fishwater00
    started a topic Segmentation fault--allocation error?
    in C

    Segmentation fault--allocation error?

    First of all, I need to thank all friends helping me here. Those days I learn a lot from your advices.
    The basic idea of my code is to read velocity file into domain[i].velocity[k] seperately.
    Start!!!
    Code:
    typedef struct
    {int nx, ny, nz;
      float *velocity;
    }
    
    void a(Model *domain, int i);
    void init(Model *domain, int steps);
    
    void main()
    {int i, j;
     int
    ...
    See more | Go to post

  • fishwater00
    replied to error: incompatible types in assignment
    in C
    I modified my codes like you said, it works now. Thank you very much....
    See more | Go to post

    Leave a comment:


  • Thanks. What do you mean "calling method"?

    If I call function "a( )" from main, I can use
    Code:
    void a(Model *domain, int t)  /* domain is the name of struct */
    It should be right, isnt it?...
    See more | Go to post

    Leave a comment:


  • fishwater00
    started a topic error: incompatible types in assignment
    in C

    error: incompatible types in assignment

    Question 1:
    Code:
        typedef struct
    	{ int x, y, z ;
    	  float *wave;
    	  float *velocity;
    	}Model;
    
    	void a(Model *domain);
    	void b(Model *domain, int t);
    
    
    	int main()
    	{int i;
    	 int j=10;
    
    	 Model Domain;
    	 Domain=(Model *)malloc(sizeof(Model);  
    
    	 for (i=0; i<10; i++)
    	    a(domain);
    
    	 return;
    ...
    See more | Go to post

  • Thank you. I use gcc to compile it ( I call it "try.c":
    [code=c]
    typedef struct
    {int x, int y, int z;
    short *velocity ;
    float *wave ;
    }Modeldim;

    void a(Modeldim *domain) ;
    void b(Modeldim *domain, int k) ;
    void c(Modeldim *domain, int k);

    int main()
    { int STEPS=10;
    int first = 10;

    Modeldim Domain;
    Domain...
    See more | Go to post

    Leave a comment:


  • Great! Thanks a lot.

    Another question is about memory allocation.

    If I don't use struct, just define like:

    [code=c]
    float velocity, wave ;
    [/code]

    I need to allocate dynamic memory for them:

    [code=c]
    velocity = my_malloc(NX, NY, NZ, sizeof(float)) ;
    wave = my_malloc((NX, NY, NZ, sizeof(float)) ;

    /* my_malloc is a function which...
    See more | Go to post

    Leave a comment:


  • Thanks. I modified my codes and paste here:

    [code=c]

    typedef struct
    { int x, int y, int z;
    short *velocity ;
    float *wave ;
    }Modeldim;

    void a(Modeldim *domain) ;
    void b(Modeldim *domain, int k) ;
    void c(Modeldim *domain, int k);

    int main()
    { int STEPS=10;
    int first = 10;

    Modeldim Domain;
    Domain = (Modeldim...
    See more | Go to post

    Leave a comment:


  • Thank you. I am going to test it.

    So far I want to figure out my struct problem:

    May I call the parameters of array which are included in "hisfunc" and "herfunc" in main after I define parameters in "myfunction(arr ay)"? Does it has some "gramma" errors?
    See more | Go to post

    Leave a comment:


  • I haven't tried to compile it. It is just a part of my whole codes. So I have to figure out this problem and move further.

    Thanks.
    See more | Go to post

    Leave a comment:


  • Thank you. I am still confused about the struct.

    [code=c]
    typedef struct
    { int x;
    int y;
    int z;
    } Modeldim ;

    void myfunction(Mode ldim *submodel)

    int main()
    {
    int x,y,z;

    Modeldim array[100];

    myfunction(Mode ldim &array);

    for (i=0; i<3; i++)
    {
    hisfunc(arr...
    See more | Go to post

    Leave a comment:


  • How to call the function including arrays of structure in main.c?

    First of all, thanks!

    I have a problem about the arrays of structure in C, the following is my codes:

    #include "system.h"

    typedef struct
    { int x, int y, int z;
    short *velocity ;
    float *wave ;
    } Modeldim ;

    void myfunction(Mode ldim *submodel) ;

    int main(int argc, char *argv[])
    {
    int X=Y=Z=1000;
    int i,j,k;...
    See more | Go to post
No activity results to display
Show More
Working...