Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

very simple

Posted on 2000-03-07
10
242 Views
Last Modified: 2010-04-15
Type TSortarray = array [ 1..10] of integer;

what's the equivalent in c?
0
Comment
Question by:anemos
10 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 2592278
typedef struct {int x[11];} TSORT;

main()
{
      TSORT z;

      z.x[10] = 69;

      printf("equal %i",z.x[10]);
}
0
 
LVL 1

Expert Comment

by:940961sl
ID: 2592290
Thats not so very simple ... In c, array's start at 0 instead of 1.

typedef int TSortarray[10]

is the equivalent of

Type TSortarray = array [0 .. 9] of integer;

in your code.

You better learn to work with arrays that start with index 0, unless you want to do a lot of index translation, if you plan to program in C.

Hope this helps ...
0
 

Author Comment

by:anemos
ID: 2592333
Adjusted points to 30
0
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:anemos
ID: 2592334
Thanks for your help... I am actually aware of the fact that the first array element is suscribted with 0. What I am wanting to know is whether it is possible to define a type int[n], where n is an integer, and then whenever I need to use an array of n elements just declare :
      type_array_10_elements   myvariable

 just like in pascal.

 thanks for your time.
0
 

Author Comment

by:anemos
ID: 2592387
moreover one has to remember that x (regarding the 1st answer) in order to use that type.
0
 
LVL 3

Expert Comment

by:msmits
ID: 2592484
In C you usually do something like:

typedef double MyType;            /* or whatever you like best */
typedef struct { int a; double b; } MyType2;

MyType my_array_var[400];
MyType2 my_array_var[20];
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2592994
i didn't write in c for a long time so i don't remember it exectlly

you can use something named macro

#define TSORT(x) int x [10]

int main(){
   TSORT(x);
   TSORT(y);
   TSORT(zarray);
   ...
}

about the fact that the array start from 0
you can write a struct array
and make there some methods that will
make it looks that your array starts from x and goes till y
and you"ll use and index-x to transfer it to 0 to y-x

and you can use the maxcro on the struct
0
 
LVL 1

Accepted Solution

by:
940961sl earned 30 total points
ID: 2596298
typedef int TSortArray[10];

void main(void)
{
   TSortArray              Array;

   Array[0] = 1;
}
0
 

Author Comment

by:anemos
ID: 2612498
I am afraid that I can't use a macro... having some difficulties with the sise operator..
0
 

Author Comment

by:anemos
ID: 2612503
Exactly what I wanted.. Thanx all of you for your response and your time..
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question