From 6981980ad5698e135b4185ef9fc5f3026509d88c Mon Sep 17 00:00:00 2001 From: Jacob Ward Date: Thu, 18 Feb 2016 13:02:55 -0700 Subject: [c/en] typos --- c.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index d92d2ee6..d4ff529d 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -723,8 +723,8 @@ typedef void (*my_fnp_type)(char *); /******************************* Header Files ********************************** Header files are an important part of c as they allow for the connection of c -source files and can simplify code and definitions by seperating them into -seperate files. +source files and can simplify code and definitions by separating them into +separate files. Header files are syntactically similar to c source files but reside in ".h" files. They can be included in your c source file by using the precompiler @@ -764,7 +764,7 @@ enum traffic_light_state {GREEN, YELLOW, RED}; Node createLinkedList(int *vals, int len); /* Beyond the above elements, other definitions should be left to a c source */ -/* file. Excessive includeds or definitions should, also not be contained in */ +/* file. Excessive includes or definitions should, also not be contained in */ /* a header file but instead put into separate headers or a c file. */ #endif /* End of the if precompiler directive. */ -- cgit v1.2.3 From bb74c468c2673de7ff92cd63830d93c455e18a33 Mon Sep 17 00:00:00 2001 From: Divay Prakash Date: Thu, 3 Mar 2016 11:41:52 +0530 Subject: fixed whitespaces removed whitespaces all over document --- c.html.markdown | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index d4ff529d..06673588 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -8,6 +8,7 @@ contributors: - ["Marco Scannadinari", "https://marcoms.github.io"] - ["Zachary Ferguson", "https://github.io/zfergus2"] - ["himanshu", "https://github.com/himanshu81494"] + - ["Divay Prakash", "https://github.com/divayprakash"] --- Ah, C. Still **the** language of modern high-performance computing. @@ -36,7 +37,6 @@ Multi-line comments don't nest /* Be careful */ // comment ends on this line... enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT}; // MON gets 2 automatically, TUE gets 3, etc. - // Import headers with #include #include #include @@ -114,7 +114,6 @@ int main (int argc, char** argv) // sizeof(obj) yields the size of the expression (variable, literal, etc.). printf("%zu\n", sizeof(int)); // => 4 (on most machines with 4-byte words) - // If the argument of the `sizeof` operator is an expression, then its argument // is not evaluated (except VLAs (see below)). // The value it yields in this case is a compile-time constant. @@ -130,7 +129,6 @@ int main (int argc, char** argv) int my_int_array[20]; // This array occupies 4 * 20 = 80 bytes // (assuming 4-byte words) - // You can initialize an array to 0 thusly: char my_array[20] = {0}; @@ -347,7 +345,6 @@ int main (int argc, char** argv) this will print out "Error occured at i = 52 & j = 99." */ - /////////////////////////////////////// // Typecasting /////////////////////////////////////// @@ -386,7 +383,6 @@ int main (int argc, char** argv) // (%p formats an object pointer of type void *) // => Prints some address in memory; - // Pointers start with * in their declaration int *px, not_a_pointer; // px is a pointer to an int px = &x; // Stores the address of x in px @@ -432,7 +428,6 @@ int main (int argc, char** argv) printf("%zu, %zu\n", sizeof arraythethird, sizeof ptr); // probably prints "40, 4" or "40, 8" - // Pointers are incremented and decremented based on their type // (this is called pointer arithmetic) printf("%d\n", *(x_ptr + 1)); // => Prints 19 @@ -578,8 +573,6 @@ void testFunc2() { } //**You may also declare functions as static to make them private** - - /////////////////////////////////////// // User-defined types and structs /////////////////////////////////////// @@ -696,6 +689,7 @@ typedef void (*my_fnp_type)(char *); "%o"; // octal "%%"; // prints % */ + /////////////////////////////////////// // Order of Evaluation /////////////////////////////////////// @@ -786,4 +780,4 @@ Readable code is better than clever code and fast code. For a good, sane coding Other than that, Google is your friend. -[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member +[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member \ No newline at end of file -- cgit v1.2.3 From f29bc250279790269315aa0258f96134390e3c61 Mon Sep 17 00:00:00 2001 From: Divay Prakash Date: Sat, 12 Mar 2016 13:39:06 +0530 Subject: fixed --- c.html.markdown | 1 - 1 file changed, 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 06673588..7c9dd590 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -8,7 +8,6 @@ contributors: - ["Marco Scannadinari", "https://marcoms.github.io"] - ["Zachary Ferguson", "https://github.io/zfergus2"] - ["himanshu", "https://github.com/himanshu81494"] - - ["Divay Prakash", "https://github.com/divayprakash"] --- Ah, C. Still **the** language of modern high-performance computing. -- cgit v1.2.3 From 7b78232897c00ebb781f28a21b96f1863c073ac8 Mon Sep 17 00:00:00 2001 From: Ryan Rauschenberg Date: Tue, 22 Mar 2016 11:15:26 -0400 Subject: issue 2205: Change variable 'size' to 'array_size' --- c.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 7c9dd590..2fad5348 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -143,9 +143,9 @@ int main (int argc, char** argv) // can be declared as well. The size of such an array need not be a compile // time constant: printf("Enter the array size: "); // ask the user for an array size - int size; - fscanf(stdin, "%d", &size); - int var_length_array[size]; // declare the VLA + int array_size; + fscanf(stdin, "%d", &array_size); + int var_length_array[array_size]; // declare the VLA printf("sizeof array = %zu\n", sizeof var_length_array); // Example: -- cgit v1.2.3 From 02db6f2bfcb8371a29a708ca425f8785615da969 Mon Sep 17 00:00:00 2001 From: Michal Jurosz Date: Thu, 12 May 2016 10:15:30 +0200 Subject: Fix c - the first character of ILoveC is I not i (#2253) --- c.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 2fad5348..babf0954 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -238,7 +238,7 @@ int main (int argc, char** argv) // Increment and decrement operators: char *s = "ILoveC"; int j = 0; - s[j++]; // => "i". Returns the j-th item of s THEN increments value of j. + s[j++]; // => "I". Returns the j-th item of s THEN increments value of j. j = 0; s[++j]; // => "L". Increments value of j THEN returns j-th value of s. // same with j-- and --j @@ -779,4 +779,4 @@ Readable code is better than clever code and fast code. For a good, sane coding Other than that, Google is your friend. -[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member \ No newline at end of file +[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member -- cgit v1.2.3 From 21c4be47790c230cf5a321aeabb5c07ad57f0522 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 17 Aug 2016 13:25:32 -0600 Subject: Remove undefined behavior (#2332) --- c.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index babf0954..92f07fe2 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -449,7 +449,8 @@ int main (int argc, char** argv) int size = 10; int *my_arr = malloc(sizeof(int) * size); // Add an element to the array - my_arr = realloc(my_arr, ++size); + size++; + my_arr = realloc(my_arr, sizeof(int) * size); my_arr[10] = 5; // Dereferencing memory that you haven't allocated gives -- cgit v1.2.3 From c8fb84cc91f9d852f38bd961af974949ffcc82e5 Mon Sep 17 00:00:00 2001 From: Jakukyo Friel Date: Tue, 13 Sep 2016 20:14:28 +0800 Subject: c: init array with string literals not introduced. (#2369) * c: fix using pointer before introduced. * c: init array with string literals not introduced. To avoid using the concept pointer before it has been introduced, previously it is changed to array. But as @geoffliu pointed out, array initialization using string literals is not introduced either. So this commit uses neither pointer nor array. Discussing `i++` and `++i` does not need to involve pointer or array. * c: use `var = value` instead of `->`. `->` is typically used for functions. Thanks, @vendethiel. --- c.html.markdown | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 92f07fe2..3fb6a83e 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -236,11 +236,9 @@ int main (int argc, char** argv) z = (e > f) ? e : f; // => 10 "if e > f return e, else return f." // Increment and decrement operators: - char *s = "ILoveC"; int j = 0; - s[j++]; // => "I". Returns the j-th item of s THEN increments value of j. - j = 0; - s[++j]; // => "L". Increments value of j THEN returns j-th value of s. + int s = j++; // Return j THEN increase j. (s = 0, j = 1) + s = ++j; // Increase j THEN return j. (s = 2, j = 2) // same with j-- and --j // Bitwise operators! -- cgit v1.2.3 From 4dee8dd033aa0ddb040463cb45791dd77cdb183b Mon Sep 17 00:00:00 2001 From: Subhrajyoti Sen Date: Wed, 28 Sep 2016 01:25:01 +0530 Subject: Update c.html.markdown (#2385) --- c.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 3fb6a83e..ae87ca08 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -511,6 +511,7 @@ void str_reverse(char *str_in) str_in[len - ii - 1] = tmp; } } +//NOTE: string.h header file needs to be included to use strlen() /* char c[] = "This is a test."; -- cgit v1.2.3 From b95bbd93f099e088b88ce307d7ddb3be85f2ca99 Mon Sep 17 00:00:00 2001 From: George Gognadze Date: Mon, 31 Oct 2016 03:35:31 +0400 Subject: C/en typo, formatting fixes (#2537) Space should be removed. Before: // Access struct members with . After: // Access struct members with. C should be capitalized. Before: // there is no Boolean type in c. We use ints instead. After: // there is no Boolean type in C. We use ints instead. Before: Header files are an important part of c as they allow for the connection of c After: Header files are an important part of C as they allow for the connection of C Before: Header files are syntactically similar to c source files but reside in ".h" After: Header files are syntactically similar to C source files but reside in ".h" Before: files. They can be included in your c source file by using the precompiler After: files. They can be included in your C source file by using the precompiler Before: as the c file. After: as the C file. Before: /* should instead be put in a c file. */ After: /* should instead be put in a C file. */ Before: /* Beyond the above elements, other definitions should be left to a c source */ After: /* Beyond the above elements, other definitions should be left to a C source */ Before: /* a header file but instead put into separate headers or a c file. */ After: /* a header file but instead put into separate headers or a C file. */ --- c.html.markdown | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index ae87ca08..57ce72d2 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -202,7 +202,7 @@ int main (int argc, char** argv) 11 % 3; // => 2 // Comparison operators are probably familiar, but - // there is no Boolean type in c. We use ints instead. + // there is no Boolean type in C. We use ints instead. // (Or _Bool or bool in C99.) // 0 is false, anything else is true. (The comparison // operators always yield 0 or 1.) @@ -715,14 +715,14 @@ typedef void (*my_fnp_type)(char *); /******************************* Header Files ********************************** -Header files are an important part of c as they allow for the connection of c +Header files are an important part of C as they allow for the connection of C source files and can simplify code and definitions by separating them into separate files. -Header files are syntactically similar to c source files but reside in ".h" -files. They can be included in your c source file by using the precompiler +Header files are syntactically similar to C source files but reside in ".h" +files. They can be included in your C source file by using the precompiler command #include "example.h", given that example.h exists in the same directory -as the c file. +as the C file. */ /* A safe guard to prevent the header from being defined too many times. This */ @@ -753,12 +753,12 @@ enum traffic_light_state {GREEN, YELLOW, RED}; /* Function prototypes can also be defined here for use in multiple files, */ /* but it is bad practice to define the function in the header. Definitions */ -/* should instead be put in a c file. */ +/* should instead be put in a C file. */ Node createLinkedList(int *vals, int len); -/* Beyond the above elements, other definitions should be left to a c source */ +/* Beyond the above elements, other definitions should be left to a C source */ /* file. Excessive includes or definitions should, also not be contained in */ -/* a header file but instead put into separate headers or a c file. */ +/* a header file but instead put into separate headers or a C file. */ #endif /* End of the if precompiler directive. */ -- cgit v1.2.3 From cc782a7cf279cf607872b86815322d617f0e2468 Mon Sep 17 00:00:00 2001 From: Louis-Philippe Asselin Date: Sun, 12 Feb 2017 13:33:22 -0500 Subject: fix further reading url (#2655) Original link displays "This file has moved to process/coding-style.rst" --- c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 57ce72d2..6d111be6 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -775,7 +775,7 @@ If you have a question, read the [compl.lang.c Frequently Asked Questions](http: It's very important to use proper spacing, indentation and to be consistent with your coding style in general. Readable code is better than clever code and fast code. For a good, sane coding style to adopt, see the -[Linux kernel coding style](https://www.kernel.org/doc/Documentation/CodingStyle). +[Linux kernel coding style](https://www.kernel.org/doc/Documentation/process/coding-style.rst). Other than that, Google is your friend. -- cgit v1.2.3 From 98f213bc68fe549df5ddcbcc131036ab6cae72ea Mon Sep 17 00:00:00 2001 From: Tyler Chong Date: Mon, 22 May 2017 22:37:46 -1000 Subject: Update c.html.markdown (#2734) --- c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 6d111be6..3da269f9 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -269,7 +269,7 @@ int main (int argc, char** argv) // While loops exist int ii = 0; - while (ii < 10) { //ANY value not zero is true. + while (ii < 10) { //ANY value less than ten is true. printf("%d, ", ii++); // ii++ increments ii AFTER using its current value. } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " -- cgit v1.2.3 From bea057020fb1a410fcb0f60a925deaf464d596a1 Mon Sep 17 00:00:00 2001 From: Aaroh Mankad Date: Fri, 26 May 2017 13:02:32 -0700 Subject: [c/en-en] Make reference link in footer/summary link to Stack Overflow article (#2739) * Make reference link in footer/summary link to Stack Overflow article * remove name from list of contributors --- c.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'c.html.markdown') diff --git a/c.html.markdown b/c.html.markdown index 3da269f9..18503eab 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -779,4 +779,4 @@ Readable code is better than clever code and fast code. For a good, sane coding Other than that, Google is your friend. -[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member +[1] [Why isn't sizeof for a struct equal to the sum of sizeof of each member?](http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member) -- cgit v1.2.3