I have the following on AIX 6.1:
#include <stdio.h>
#include <stdlib.h>
int main(){
#if defined(__AIX)
printf("hello world");
#endif
return 0;
}
I have followed the instructions from http://predef.sourceforge.net/preos.html#sec2 but am scratching my head as to why it does not work or print out "hello world" when I run it?
if I do a "uname" on the box I get "AIX"...and "uname -v" returns "6"...
Any ideas what I can put into the code?
Thanks for the help
Lynton
should be 1 underscore not 2 underscores before "AIX"....solved now ;-)
Related
I have this basic code in C. A program to say 'Hello World'. And the first line That say #include <stdio.h> is underlined in red as though an error is occurred.
#include<stdio.h>
main()
{
printf("hello, world\n")
}
I'm using vs code to run the program, is it a bug in vs code? or maybe a problem in the installation of C?
please help.
I don't understand where the problem originates so no actions have been pursued.
Add space between #include and <stdio.h>
Also, specify the return type of your main function.
Also at the end of printf("hello, world\n"), there should be semi colon
#include <stdio.h>
void main(){
printf("hello, world\n");
}
it is void since it is not returning anything.
I don't know what to do
please can any one help me
I'm trying to use c in vs code for the first time
#include <stdio.h>
int main (void)
{
printf("Hello, World!");
}
The problem
I can't seem to get termcap's "cl" command to work, but the terminal escape code does.
For example:
#include <termcap.h>
#include <stdio.h>
int main()
{
tputs(tgetstr("cl", NULL), 1, putchar);
}
This doesn't change the terminal. But when I run:
#include <stdio.h>
int main()
{
printf("\e[2J");
}
or if I call echo `tput cl`
The terminal is cleared.
Why does this happen? Shouldn't termcap give that same escape code?
EDIT: Fixed writing characters
EDIT2: It's because i didn't call tgetent() before calling tgetstr(). Thanks guys!
Before interrogating with tgetstr(), you need to find the description of the user's terminal with tgetent():
#include <stdio.h>
#include <stdlib.h> // getenv
#include <termcap.h> // tgetent tgetstr
int main(void)
{
char buf[1024];
char *str;
tgetent(buf, getenv("TERM"));
str = tgetstr("cl", NULL);
fputs(str, stdout);
return 0;
}
Compile with -ltermcap
I'm trying to run a unix compiler-project written in c with MS Visual-Studio 2013 and I can't get rid of the following error:
error LNK2019: unresolved external symbol "_snprintf" referenced in
function "PUBLIC void SyntaxError( int Expected, TOKEN CurrentToken )"
If I get it right it is a problem where VisualStudio can't find the body/declaration from the snprintf() function, which should be defined in stdio.h.
The project works fine with cygwin. I had to add _CRT_SECURE_NO_WARNINGS to preprocessor settings to get this far, but i don't think that has a influence.
Here is the named function:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "line.h"
#include "strtab.h"
#include "scanner.h"
[..code..]
PUBLIC void SyntaxError( int Expected, TOKEN CurrentToken )
{
char s[M_LINE_WIDTH+2];
snprintf( s, sizeof(s), "Syntax: Expected %s, got %s\n", Tokens[Expected], Tokens[CurrentToken.code] );
Error( s, CurrentToken.pos );
}
If you can help me or there is anything else you need to know please tell me. It's my 3rd day now and I am running out of ideas ;).
So far... Tobias
The name of this function with the MSVC compiler is _snprintf() with an underscore.
I was trying to set the timezone of my system, and was trying to use settimeofday(), which takes a timezone struct as an argument, but just read that that struct is now obsolete (http://linux.about.com/library/cmd/blcmdl2_settimeofday.htm) How could I go about doing this?
Thanks in advance.
EDIT: Ugh, I feel really stupid.
I created a link.c and compiled it:
#include <stdio.h>
void main()
{
printf("This is the link \n");
}
Created a target.c, and compiled it:
#include <stdio.h>
void main()
{
printf("This is the target \n");
}
and then tried the symlink function in a test program:
#include <unistd.h>
void main()
{
int garbage = symlink("/home/imandhan/pythonTests/link", "/home/imandhan/pythonTests/target");
printf(garbage);
}
This gives me a segmentation fault for some reason. Am I doing something wrong?
See tzset(3) for setting timezone for an application.
For the whole system - symlink /etc/localtime to appropriate file under /usr/share/zoneinfo/.