Questions tagged [ansi-c]

ANSI C is an informal term sometimes used when referring to the C programming language standard published by the American National Standards Institute (ANSI) in 1989 .

"ANSI C" is an informal term used to refer to the 1989 version of the C language. The formal name for this version of the language is ISO/IEC 9899:1990. Informally it is also known as "C89" or "C90".

This is because the American National Standards Institute (ANSI) first published this standard in the year 1989, as a national standard for the USA. It became international ISO standard in the year 1990. So ANSI C, C89 and C90 all refer to the same technical standard.

It is a common misunderstanding that "ANSI C" means standard compliant C. The ANSI standard institute haven't had anything to do with C since 1989. The language is maintained by ISO SC22/WG14. Yet the term "ANSI C" is sometimes used to mean standard compliant, particularly in old books and by old compilers.

Because of this ambivalent meaning, please avoid using this tag. For questions regarding the C89/C90 version of the C language, please use . For questions regarding standard-compliant C, simply use the tag.

Further information about the different C standard versions.

618 questions
3
votes
5 answers

How to handle invalid passed arguments in Ansi C

I am new to C and come from a back ground of newer languages (like Java and C++) and I'm not sure how to handle runtime errors like an incorrect arguments sent to a function. for example say I want to write a function to manipulate a string…
dranobob
  • 796
  • 1
  • 5
  • 19
3
votes
1 answer

How to Write File in Reverse Order

I'm working on an ANSI C application that produces file contents in reverse order. That is, the bytes at the end of the file are received first, and those at the beginning are received last. Preferably, due to the amounts of data that may be…
Jim Fell
  • 13,750
  • 36
  • 127
  • 202
3
votes
3 answers

Recognize non-standard C++ portably?

C has __STDC__ but there seems to be no standard way of recognizing some extended C++ dialect. Hence for portable code I use #define __is_extended \ ((__GNUG__ &&!__STRICT_ANSI__) || \ …
Andreas Spindler
  • 7,568
  • 4
  • 43
  • 34
3
votes
1 answer

C: Allowed to assign any array to pointer to array of incomplete type

The following seems of questionable legality in C89. I can't figure out why it's allowed. I'm reading the standard and my copy of K&R2 and I still don't get it. char Arr[16]; char (*Durr)[] = &Arr; /*Why is this allowed?*/ That's it really. I need…
Subsentient
  • 554
  • 3
  • 12
3
votes
2 answers

What must I know to handle UTF-8 in my C program?

I have a C program that now I need to do support to UTF-8 characters. What must I know in order to perform that? I've always hear how problematic is handle it in a C/C++ environment. Why exactly is it problematic? How does it differ from an usual C…
The Mask
  • 17,007
  • 37
  • 111
  • 185
3
votes
2 answers

How to determine end of read

I have simple C server and Java client. I'm sending text file line by line from server to client: do { send(sockfd, line, strlen(line), 0); printf("%s\n", line); } while ((fgets(line, 100, fp)) != NULL); and read it in…
Stepan Tuhacek
  • 219
  • 5
  • 18
3
votes
2 answers

Segmentation fault - Core Dumped error while using getopt

I know this queston has been asked multiple times, but still I am unable to figure this out #include #include int ch; int queue_time=60; int thread_num=4; char *scheduling_algo="FCFS"; extern char *optarg; int port=8080; int…
user2934433
  • 343
  • 1
  • 5
  • 20
3
votes
2 answers

Ansi c preprocessor: Can I concatenate macro name and argument into single variable name?

I'd like to shorten variable names, so instead of this : FPData.Temps.T.Solar.Val I'd like to use : TEMP_Solar.Val and define macro : #define TEMP_ FPData.Temps.T. But it works only if I put space in between : TEMP_ Solar.Val compiles ok,…
user2152780
  • 53
  • 2
  • 6
3
votes
2 answers

Assignment to un-initialised Integer Pointer

How is the value 2 being stored since the pointer has not been initialised in the following code snippet ? int *p; *p = 2; printf("%d %d\n",p,*p); The Output for the above program is as follows : 0 2 I was reading "Expert C Programming" by Peter…
Kyuubi
  • 1,228
  • 3
  • 18
  • 32
3
votes
3 answers

Making a void* within a struct point to an integer

I have a struct as follows: typedef struct Node { void* data; unsigned long id; NodePtr next; NodePtr prev; } Node; It is meant to be a node in a linked list ADT. I have 2 different constructors depending on what the Node needs to…
Ethan Lie
  • 41
  • 1
  • 2
3
votes
1 answer

Can TCC be modified to compile with Emscripten? If not, where can I find an x86-generating C compiler that does?

After unzipping tcc-0.9.26, I edit configure to point at emcc instead of gcc and at emar instead of ar. Next, I uncomment the include of ucontext in tcc.h since it seems to be needed only for tccrun. Now I disable all the builtins (sub_ddmmss and so…
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
3
votes
3 answers

Are wchar_t and multibyte functions part of ANSI C?

C99 and C11 support wchar_t and multibyte functions .But I am not sure about ANSI C (1989). Is it correct that wchar_t and multibyte functions (mblen, mbstowcs, mbtowc, wcstombs, wctomb) are part of ANSI C? I don't find these functions in Kernighan…
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
3
votes
1 answer

fscanf with string and long

I'm trying to parse a file that another function has written with this fprintf: fprintf(file, "DS;%s;%ld;%ld;%u\n", ds->name, ds->start, ds->period, ds->size) I'm using this fscanf: fscanf(file, "DS;%[^;$]s;%ld;%ld;%u", file_name, &file_start,…
3
votes
1 answer

Forecast a struct

I believe what I am looking for is referred to as forecasting... I want to typedef a Function Pointer that refers to a struct, and then that Function pointer is stored in the struct. See ShellCmdDEF below. typedef BOOL (*ShellCmdFN) (struct…
Syntactics
  • 313
  • 4
  • 8
3
votes
1 answer

ANSI C - Count words and letters per line

I'm working on a personal project,but I have no idea how to do it: Count the words (each word costs $5 usd) Count the letters per word (if the word has less than 4 letters costs $4 USD, if is more than 4 letters it costs $5 USD) This is my code…
Daniel
  • 378
  • 1
  • 6
  • 20