#include <stdio.h>
#include <stdlib.h>
struct rithish
{
    int roll;
    char name;
}*s[20];

void main()
{
    struct rithish *s;
    int i;
    for(i=0;i<2;i++)
    {
        printf("\n\n\t Enter roll : ");
        scanf("%d",&*s[i].roll);
        printf("\n\n\t enter name: ");
        scanf("%s",&*s[i].name);
    }

}

is it possible to do structure variable as pointer to array

#include <stdio.h>
#include <stdlib.h>
struct rithish
{
    int roll;
    char name;
}*s[20];

void main()
{
    struct rithish *s;
    int i;
    for(i=0;i<2;i++)
    {
        printf("\n\n\t Enter roll : ");
        scanf("%d",&s[i]->roll);
        printf("\n\n\t enter name: ");
        scanf("%s",&->s[i]->name);
    }

}

how to do this i have to insert data inside the array using structures of pointers

Edited 4 Years Ago by rithish

MAIN IS NOT A VOID FUNCTION! STOP USING VOID!!! If you want to program correctly, USE THE HELP WE'VE GIVEN YOU!!!

ok waltp ill do that what is difference between using void main() and int main() because void means it returns empty .but int returns 0

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HOW_MANY_STRUCTS 20
#define MAX_NAME_LENGTH 30
typedef struct ritnish
{
    int iRoll;
    char pcName[MAX_NAME_LENGTH];
}stRitnish;

int main()
{
   stRitnish s[HOW_MANY_STRUCTS] = {0};
   srand(time(NULL));
   memcpy(s[0].pcName, "TestName!",sizeof("TestName!"));
   s[0].iRoll = rand() % 1000;
   printf("Printing name [%s] and number %d\n", s[0].pcName, s[0].iRoll);

   return 0;
}

ok waltp ill do that what is difference between using void main() and int main() because void means it returns empty .but int returns 0

what is empty ?
there is no magic, value is value i suppose

Rithish: The issue is not in the behavior of the two forms of the function, but rather is in the wording of the C language standard, and less directly, in the behavior of the majority operating system shells. You see, it isn't incidental that main() was type int even in the days of default return values; it was intentional behavior. The return value of the program isn't simply discarded, it is returned to the program which initiated the program run, usually the command shell.The returned value is used as an indicator of the program completion status - 0 means it ran to completion without any fatal errors, any other value indicates that something went wrong. In Unix (and it's descendants, Linux and MacOS X), there is even a standarsd list of error messages one can return, though it is rarely used.

The value isn't always, or even often, used, though it does play an important role in shell script programming, where a half dozen or more different programs may be run by a single script, any of hich could, theoretically, fail.

Also, not every OS uses the value in a meaningful way. Windows doesn't generally do anything with it, though it is capable of it for batch scripting; most embedded systems don't have anything to return to, or else have some less generic method of catching errors.

Prior to 1986 or so, this wasn't a big deal, because it was stadard practice to use a default return value, like this:

 main()
 {
 /* do something */
 }

for both int valued functions and valueless functions. The compilers of the day were far more forgiving, by design - the language was intended for Systems Programming Experts Only, after all, and even the creators used Ratfor and Pascal for everyday programming - so there wasn't much in the way of typechecking, anyway, a feature widely exploited at the time. The practical upshot of this was that an int and a 'void' looked pretty much the same anyway, so no one really bothered to get worked up about it.

By 1986, however, the worm had turned. As the language became popular even - or should I say, especially - in circles it was never intended for, it's deficiencies became more and more glaring, and the lack of a consistent language definition became acute. Thus, the American National Standards Institute formed a committee to regularize and standardize the C language.

One thing the ANSI committee proposed was eliminating default function types, which would make the language more regular and easier to read, and enforcing return types. This left them with the question of what to do about functions that had nop return in the first place. Thus, to fill this and several other holes in the typing system, they introduced the void type declaration, it was not unusual for programmers on those systems to say, "I've never needed a return type for main() before, why should I start now? I know, I'll use void for it, then everyone will be sure what I'm talking about and I can skip this silly return 0; business!"

All well and good, except for one thing: programs writtn this way now would run properly on Unix systems, which were still the native environment for the C language. This was a Serious Problem, as Unix was as almost as much the dominant platform then as Windows is today, at least for larger systems and in universities. The Unix people howled at this obvious Wrong practice, and demanded that the standards committee Do Something.

Not surprisingly, the other programmers, especially on embedded systems, howled back. "How can main() return to a system that isn't there?", they asked, "This is a preposterous requirement!"

In the face of this, the old ANSI committee bravely... equivocated. They stated that the standard return value for main() would be int, and that only int main() was portable... but whether this was actually required by the compiler was 'implementation dependent'. Later ISO committes kept this state of affairs through C99, but in the C11 standard, the question was finally decided: int, and only int, was the correct return value for main(), and void main() was formally abolished in those compilers which implement the new standard.

Now, just to make sure everyone is clear on the difference between the two languages, I should add that int main() has always been required in C++, even if some compilers chose to ignore Bjarne's rather pointed opions on the subject.

I should also, in all fairness, admit that I was one of the mistaken 'early adopters' of void main() when I was first learning C myself, around the time all of this was first happening (circa 1988), and it took me years to break the habit. It's much better for everyone if you simply don't start using it to begin with.

Do You Believe That?(TM)

Edited 4 Years Ago by Schol-R-LEA

Comments
Nice.
This article has been dead for over six months. Start a new discussion instead.