SVMAYOL <twin_f...@...> wrote:
>
> im using borland C... and doing this stuff..(im just
> practicing using this SW)
Can you run simpler programs? E.g...
#include <stdio.h>
int main(void) { puts("Hello World"); return 0; }
> #include<stdio.h>
> #include<conio.h>
Does it work without the <conio.h> crud?
> #include<string.h>
> main()
You should put an explicit return type...
int main()
> {
> char ako;
This allocates 1 byte of storage. It's not enough to hold
anything but an empty string.
> int edad;
> clrscr();
> printf("enter your name:");
Better to include a newline. If you want the text to appear
before the prompt, then you should fflush(stdout) prior to
reading input.
> scanf("%s",ako);
Your reference text for C should advise that scanf's %s
requires a pointer to a character sequence, not a character.
You should also check the return value of any input function
to make sure you actually received input.
> printf("\nenter your age:");
> scanf("%d",&edad);
> gotoxy(30,15);
> printf("My Name is %s, and I am %d",ako,edad);
> getch();
Don't bother with getch(). Learn to run code from a terminal
window.
> }
>
> my problem is the error states that: unable to create
> output file.object when i tried to run it..=)
Does it compile?
Does it link?
Are you using an IDE, or are you working from the command
line?
% type hello.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char name[50], *nl;
int age;
printf("Enter your name: ");
fflush(stdout);
if (!fgets(name, sizeof name, stdin))
return EXIT_FAILURE;
nl = strchr(name, '\n');
if (nl) *nl = 0;
if (name[0] == 0) return EXIT_FAILURE;
printf("Enter your age (years): ");
fflush(stdout);
if (scanf("%4d", &age) != 1)
return EXIT_FAILURE;
printf("Your name is %s and your age is %d years.\n", name, age);
return 0;
}
% acc hello.c -o hello.exe
% hello
Enter your name: Bill Gates
Enter your age (years): 53
Your name is Bill Gates and your age is 53 years.
%
Note that acc is my ANSI C compiler (DJGPP).
--
Peter