C String ‘i Ondalıklı Sayıya Çevirmek

Standart C kütüphanesinden double atof(const char *str) ile bir metini ondalıklı sayıya çevirebiliriz.


int main()
float val;
char str[20];

strcpy(str, “98993489”);
val = atof(str);
printf(“String value = %s, Float value = %f\n”, str, val);

strcpy(str, “tutorialspoint.com”);
val = atof(str);
printf(“String value = %s, Float value = %f\n”, str, val);


C library function – strcat()

strcat iki string ‘i bitişik olarak ekler.


int main ()
char src[50], dest[50];

strcpy(src, “This is source”);
strcpy(dest, “This is destination”);

strcat(dest, src);

printf(“Final destination string : |%s|”, dest);


C Dili Öğreniyorum

Understanding the C Language Skeleton
Most coding starts with a C language structure. This skeleton includes the basic bones upon which most programs are written. Use this simple skeleton to get started:

int main()
Traditionally, the program begins with preprocessor directives plus prototypes. The #include statements bring in header files, such as stdio.h, the standard input/output header file.

The primary function in all C code is main(), which is the first function that’s run when the program starts. The main() function is an int function, so it must return an integer value. All the function’s statements are enclosed in curly brackets, or braces.

C Language Keywords
The C language keywords represent the core of the language. With the C11 revision to the language, several new keywords have been added. They’re shown with leading underscores in the following table:

_Alignas break float signed
_Alignof case for sizeof
_Atomic char goto static
_Bool const if struct
_Complex continue inline switch
_Generic default int typedef
_Imaginary do long union
_Noreturn double register unsigned
_Static_assert else restrict void
_Thread_local enum return volatile
auto extern short while
Keep the following points in mind as you start programming in C:

Do not name any function or variable the same as a keyword.

You use only a few of the C language keywords in your code. Some of them, you’ll probably never use.

Most of the work in your code is done by functions, not by keywords.

C Language Variable Types
Rather than make all your variables floats, it’s more efficient to examine the type of data that’s stored and then choose an appropriate C variable type.

Type Value Range
_Bool 0 to 1
char –28 to 127
unsigned char 0 to255
short int –32,768 to 32,767
unsigned short int 0 to 65,535
int –2,147,483,648 to 2,147,483,647
unsigned int 0 to 4,294,967,295
long int –2,147,483,648 to 2,147,483,647
unsigned long int 0 to 4,294,967,295
float 1.17×10–38 to 3.40×1038
double 2.22×10–308 to 1.79×10308
Keep these C language variable type points in mind:

Ensure that you choose the proper variable type for the values you need to store.

The _Bool type stores only two values, 0 and 1, which can represent TRUE or FALSE or On or Off or any binary condition.

The char variable type stores character values, though it can also be used to store tiny integers.

Integers, or whole numbers, are stored in the int variable types.

Any type of value, from the very large to the very small, and any fractional values are stored in the float and double types.

Remember to use int values for functions that generate integers, such as getchar(). It’s easy to assume that the function returns a char value because of the function’s name.

C lacks a string variable type. Instead, an array of char variables is used.

Other variable types include structures and pointers.

Common C Escape Sequences
When you cannot type characters into your string, use the escape sequences to insert nonprintable characters into text strings, char variables, and arrays. Here are common C escape sequences:

Characters What It Represents or Displays
\a Bell (“beep!”)
\b Backspace, non-erasing
\f Form feed or clear the screen
\n Newline
\r Carriage return
\t Tab
\v Vertical tab
\\ Backslash character
\? Question mark
\’ Single quote
\” Double quote
\xnn Hexadecimal character code nn
\onn Octal character code nn
\nn Octal character code nn
Using escape sequences is the secret way to embed characters you cannot type into a string, or to test for those characters in a conditional statement or for regular input. Even printable characters can be coded by using an escape sequence. The \x hexadecimal and \nn sequences can represent any ASCII character.

Common C Conversion Characters
The printf() and scanf() functions use conversion characters as placeholders for various values. Conversion characters are used to indicate a value when the function runs in the final program.

Conversion Character What It Displays
%% The percent character (%)
%c A single character (char)
%d Integer value (short, int)
%e Floating-point value in scientific notation using a little E (float, double)
%E Floating-point value in scientific notation using a big E (float, double)
%f Floating-point value in decimal notation (float, double)
%g Substitutes %f or %e, whichever is shorter (float, double)
%G Substitutes %f or %E, whichever is shorter (float, double)
%i Integer value (short, int)
%ld Long integer value (long int)
%o Unsigned octal value, no leading zero
%p Memory location in hexadecimal (*pointer)
%s String (char *)
%u Unsigned integer (unsigned short, unsigned int, unsigned long)
%x Unsigned hexadecimal value, lower case (short, int, long)
%X Unsigned hexadecimal value, capital letters (short, int long)
The Order of Precedence in C
The order of precedence determines which operators act upon a value first. When crafting statements, know the order of precedence to ensure that the program does what you intend.

Operator(s) Category Description
! Unary Logical not; associativity goes right to left
++ — Unary Increment, decrement, read from right to left
* / % Math Multiplication, division, modulo
+ – Math Addition, subtraction
<< >> Binary Shift left, shift right
< > <= >= Comparison Less than, greater than, less than or equal to, greater than or equal to
== != Comparison Is equal to, not equal to
& Binary And
^ Binary Exclusive or (XOR)
| Binary Or
&& Logical And
|| Logical Or
?: Comparison Weird if thing; associativity goes right to left
= Assignment Variable assignment operator, including the +=, *=, and all assignment operators
, (None) The comma separates items in a for statement; precedence from left to right
The order of precedence can be overridden by using parentheses. Simply enclose within a set of parentheses the part of the equation that you want executed first. That part is executed first no matter what the priority is.

C ‘de String Fonksiyonları

String functions
1 strcat ( )  Concatenates str2 at the end of str1.
2 strncat ( )  appends a portion of string to another
3 strcpy ( )  Copies str2 into str1
4 strncpy ( )  copies given number of characters of one string to another
5 strlen ( )  gives the length of str1.
6 strcmp ( )  Returns 0 if str1 is same as str2. Returns <0 if strl < str2. Returns >0 if str1 > str2.
7 strcmpi_(.)  Same as strcmp() function. But, this function negotiates case.  “A” and “a” are treated as same.
8 strchr ( )  Returns pointer to first occurrence of char in str1.
9 strrchr ( )  last occurrence of given character in a string is found
10 strstr ( )  Returns pointer to first occurrence of str2 in str1.
11 strrstr ( )  Returns pointer to last occurrence of str2 in str1.
12 strdup ( )  duplicates the string
13 strlwr ( )  converts string to lowercase
14 strupr ( )  converts string to uppercase
15 strrev ( )  reverses the given string
16 strset ( )  sets all character in a string to given character
17 strnset ( )  It sets the portion of characters in a string to given character
18 strtok ( )  tokenizing given string using delimiter