SlideShare a Scribd company logo
1 of 25
Download to read offline
DİZGELER – KARAKTER DİZİLERİ
programlama dilleri 1
- 4. hafta -
Araş. Gör. Nesibe YALÇIN
BİLECİK ŞEYH EDEBALİ ÜNİVERSİTESİ
MÜHENDİSLİK FAKÜLTESİ
BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ
2
Karakter Dizileri
― char tipli karakterlerden oluşan ve en sonuna ‘0’
(boş, NULL) karakteri eklenmiş dizilerdir.
― string, katar, dizge, dizgi de denir.
― Karakterler ‘?’, ‘1’, ‘t’, ‘+’ şeklinde tek tırnak içerisinde
yazılır, dizgeler “Bilecik” şeklinde çift tırnak içerisinde
yazılırlar.
― “Bilecik” = {‘B’, ‘i’, ‘l’, ‘e’, ‘c’, ‘i’, ‘k’, ‘0’}
3
Değer Atama
char a[] =“C dili”;
Derleyici, karakter sayısına göre otomatik
olarak dizi boyutunu ayarlıyor.
0 1 2 3 4 5 6
C d i l i 0
Adres Veri
0x00
0x01 67 ‘C’
0x02 32 ‘ ’
0x03 100 ‘d’
0x04 105 ‘i’
0x05 108 ‘l’
0x06 105 ‘i’
0x07 0 ‘0’
0x08
0x09
0x10
0x14
Derleyici
4
Değer Atama
char a[]={'C',' ','d','i','l','i','0'};
char x[] =“programlama”;
char x[]; //hatalı
NOT: Fonksiyonlarda girdi olarak kullanılabilir.
char x[25];
x[]=“programlama”; //hatalı
x=“programlama”; //hatalı
• Çok boyutlu dizilerde;
• char isim[5][8] = {“Ayse”, “Hamdi”, “Burak”, “Leyla”, “Ahmet”};
• char sehir[][10] = {“Ankara”, “Sakarya”, “Yozgat”, “Konya”};
• Stringlerde doğrudan kullanılmayan karakterler:
– Çift tırnak karakterini ekrana yaz: ”
– Tek tırnak karakterini ekrana yaz: ’
– Ters bölü karakterini ekrana yaz: 
– Yüzde karakterini ekrana yaz: %%
5
Değer Atama
6
Karakter Dizileri
#include <stdio.h>
#include <conio.h>
void main() {
char a[]="C dili";
int i=0;
while(a[i]!='0'){
printf("%c",a[i]);
i++; }
getch (); }
#include <stdio.h>
#include <conio.h>
void main() {
char a[]="C dili";
for(int i=0; i<6;i++)
printf("%c",a[i]);
getch (); }
#include <stdio.h>
#include <conio.h>
void main() {
char a[]="C dili";
printf("%s",a);
getch (); }
7
Karakter Dizileri
#include <stdio.h>
#include <conio.h>
void main() {
char a[]="C dili";
printf("%sn",a);
a[3]='0';
printf("%s",a);
getch (); }
8
Karakter Dizileri
#include <stdio.h>
#include <conio.h>
void main() {
char a[]="C dili";
printf("%sn",a);
a[6]=‘m';
printf("%s",a);
getch (); }
• puts(char str []): Ekrana stringi ekrana yazdırdıktan
sonra imleci bir sonraki satıra geçirir.
#include <stdio.h>
#include <conio.h>
void main() {
char bolum[10]="bilgisayar";
printf("%s",bolum);
// puts(bolum);
getch (); }
9
String Fonksiyonları
• gets(char str[]): Girdi olarak string almak için
kullanılır, stringin sonuna ‘0’, null karakterini
otomatik olarak ekler.
#include <stdio.h>
#include <conio.h>
void main() {
char bolum[10];
scanf("%s",bolum);
// gets(bolum);
getch (); }
10
String Fonksiyonları
• string.h kütüphanesinde yer alanlar:
• strlen(char str[]): Bir string (dizge) içindeki karakter
sayısını bulmak için kullanılır.
int adet=0;
while(str[adet]!=‘0’)
adet++;
ya da
adet=strlen(str);
11
String Fonksiyonları
• strcpy(char str1[],char str2[]): str2 stringini str1
stringine kopyalama işlemini yapar.
char ad[10];
strcpy(ad,"elanur");
• strncpy(char str1[],char str2[],int n): str2
stringindeki ilk n adet karakteri str1 stringine
kopyalama işlemini yapar.
12
String Fonksiyonları
• strcat(char str1[],char str2[]): str1 stringinin sonuna
str2 stringinin eklenmesini sağlar.
char str1[10]= “sınıf”;
char str2[10]= “C112”;
strcat(str1, str2);
str1’ in yeni hali “sınıf C112”
• strncat(char str1[],char str2[],int n): str1 stringinin
sonuna str2 stringinin ilk n karakterinin eklenmesini
sağlar.
13
String Fonksiyonları
• strcmp(char str1[],char str2[]): str1 ve str2
stringlerini karşılaştırır: Eşit ise 0, str1 stringi sözlükte
daha önce geliyorsa -1, str2 stringi daha önce
geliyorsa 1 değerini döndürür.
– strcmp(“Ankara”, “Ankara”)  0
– strcmp(“Ankara”, “Antalya”)  -1
– strcmp(“Antalya”, “Ankara”)  1
• strncmp(char str1[],char str2[],int n): str1 ve str2
stringlerinin ilk n karakterlerinin karşılaştırılmasını
sağlar.
14
String Fonksiyonları
• strrev(char str1[]): str1 stringini ters çevirir.
• strstr(char str1[],char str2[]): str1 stringi içinde str2
stringini arar, ilk karşılaştığı yeri verir.
15
String Fonksiyonları
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
char girdi[20];
puts("Bir string girin: ");
gets(girdi);
printf("%sn",strstr(girdi,"al"));
getch (); }
• strchr(char str1[],char x): str1 stringi içinde x
karakterini arar, ilk karşılaştığı yeri verir.
16
String Fonksiyonları
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char girdi[20];
puts("Bir string girin: ");
gets(girdi);
printf("%sn",strchr(girdi,'a'));
getch ();
}
• strlwr(char str1 []): str1 stringindeki büyük harfleri
küçük harflere çevirir.
• strupr(char str1 []): str1 stringindeki küçük harfleri
büyük harflere çevirir.
17
String Fonksiyonları
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
char ad[]="NeSiBe YaLCiN";
strupr(ad);
printf("%sn",ad);
strlwr(ad);
printf("%s",ad);
getch (); }
• ctype.h kütüphanesinde yer alanlar:
• isalnum(char x): Girilen x karakterin alfabetik ya da
nümerik olup olmadığını sorgular.
18
String Fonksiyonları
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
void main() {
char x;
puts("Bir karakter girin: ");
scanf("%c",&x);
if(isalnum(x))
printf("Alfabetik/Numerik");
else
printf("Alfabetik/Numerik degil");
getch (); }
• ctype.h kütüphanesinde yer alanlar:
• isalpha(char x): x bir harf ise sıfırdan farklı, diğer
durumlarda sıfır değerini döndürür.
• isdigit(char x): x bir sayı ise sıfırdan farklı, diğer
durumlarda sıfır değerini döndürür.
• isspace(char x): x boşluk, yeni satır veya tab karakteri
gibi bir karakterse sıfırdan farklı, diğer durumlarda
sıfır değerini döndürür.
19
String Fonksiyonları
• isupper(char x): x büyük bir harf ise sıfırdan farklı,
diğer durumlarda sıfır değerini döndürür.
• islower(char x): x küçük bir harf ise sıfırdan farklı,
diğer durumlarda sıfır değerini döndürür.
• sizeof(…. a): Donanım sisteminin a değişkenine ya da
veri türüne ayırdığı bellek büyüklüğünü verir.
20
String Fonksiyonları
• toupper(char x): x’ in değerinin büyük harf karşılığını
verir.
• tolower(char x): x’ in değerinin küçük harf karşılığını
verir.
21
String Fonksiyonları
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
void main() {
char x;
puts("Bir karakter girin: ");
scanf("%c",&x);
printf("%c",toupper(x));
printf("%c",tolower(x));
getch (); }
22
Uygulama Örnekleri
// #include <string.h>
#include <stdio.h>
#include <conio.h>
void main() {
char str[20]="Muhendislik";
//for(int i=0;i<strlen(str);i++)
for(int i=0;str[i]!='0';i++){
for(int j=0;j<i+1;j++)
printf("%c",str[j]);
printf("n"); }
getch(); }
23
Uygulama Örnekleri
#include <stdio.h>
#include <conio.h>
void main() {
char girdi[20];
int i=0,sayac=0;
puts("Bir string girin: ");
gets(girdi);
while(girdi[i] != '0'){
if( girdi[i] == 'a')
sayac++;
i++; }
printf("'a' karakteri sayisi = %dn",sayac);
printf("Toplam karakteri sayisi = %dn",i);
printf("Ayrilan bellek buyuklugu %d byte",sizeof(girdi));
getch (); }
24
Uygulama Örnekleri
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
char girdi[20];
int sayac=0;
puts("Bir string girin: ");
do{
gets(girdi);
sayac++;
}while( strcmp(girdi, "Ankara*06")!=0);
printf("%d seferde bildinizn",sayac);
getch (); }
• Kullanıcı tarafından girilen bir karakter dizisi içindeki
boşluk karakterini çıkaran programı C dilinde yazınız.
• strstr fonksiyonu ile aynı görevi yapan void str_arama(char
a[],char b[]) isimli kendi fonksiyonunu yazınız.
• Kullanıcı tarafından girilen bir stringin Palindrom olup
olmadığını bulan fonksiyonu yazınız.
2141412, ata, kazak, Ey Edip Adanada pide ye …
25
Uygulama Örnekleri

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Karakter dizileri

  • 1. DİZGELER – KARAKTER DİZİLERİ programlama dilleri 1 - 4. hafta - Araş. Gör. Nesibe YALÇIN BİLECİK ŞEYH EDEBALİ ÜNİVERSİTESİ MÜHENDİSLİK FAKÜLTESİ BİLGİSAYAR MÜHENDİSLİĞİ BÖLÜMÜ
  • 2. 2 Karakter Dizileri ― char tipli karakterlerden oluşan ve en sonuna ‘0’ (boş, NULL) karakteri eklenmiş dizilerdir. ― string, katar, dizge, dizgi de denir. ― Karakterler ‘?’, ‘1’, ‘t’, ‘+’ şeklinde tek tırnak içerisinde yazılır, dizgeler “Bilecik” şeklinde çift tırnak içerisinde yazılırlar. ― “Bilecik” = {‘B’, ‘i’, ‘l’, ‘e’, ‘c’, ‘i’, ‘k’, ‘0’}
  • 3. 3 Değer Atama char a[] =“C dili”; Derleyici, karakter sayısına göre otomatik olarak dizi boyutunu ayarlıyor. 0 1 2 3 4 5 6 C d i l i 0 Adres Veri 0x00 0x01 67 ‘C’ 0x02 32 ‘ ’ 0x03 100 ‘d’ 0x04 105 ‘i’ 0x05 108 ‘l’ 0x06 105 ‘i’ 0x07 0 ‘0’ 0x08 0x09 0x10 0x14 Derleyici
  • 4. 4 Değer Atama char a[]={'C',' ','d','i','l','i','0'}; char x[] =“programlama”; char x[]; //hatalı NOT: Fonksiyonlarda girdi olarak kullanılabilir. char x[25]; x[]=“programlama”; //hatalı x=“programlama”; //hatalı
  • 5. • Çok boyutlu dizilerde; • char isim[5][8] = {“Ayse”, “Hamdi”, “Burak”, “Leyla”, “Ahmet”}; • char sehir[][10] = {“Ankara”, “Sakarya”, “Yozgat”, “Konya”}; • Stringlerde doğrudan kullanılmayan karakterler: – Çift tırnak karakterini ekrana yaz: ” – Tek tırnak karakterini ekrana yaz: ’ – Ters bölü karakterini ekrana yaz: – Yüzde karakterini ekrana yaz: %% 5 Değer Atama
  • 6. 6 Karakter Dizileri #include <stdio.h> #include <conio.h> void main() { char a[]="C dili"; int i=0; while(a[i]!='0'){ printf("%c",a[i]); i++; } getch (); } #include <stdio.h> #include <conio.h> void main() { char a[]="C dili"; for(int i=0; i<6;i++) printf("%c",a[i]); getch (); } #include <stdio.h> #include <conio.h> void main() { char a[]="C dili"; printf("%s",a); getch (); }
  • 7. 7 Karakter Dizileri #include <stdio.h> #include <conio.h> void main() { char a[]="C dili"; printf("%sn",a); a[3]='0'; printf("%s",a); getch (); }
  • 8. 8 Karakter Dizileri #include <stdio.h> #include <conio.h> void main() { char a[]="C dili"; printf("%sn",a); a[6]=‘m'; printf("%s",a); getch (); }
  • 9. • puts(char str []): Ekrana stringi ekrana yazdırdıktan sonra imleci bir sonraki satıra geçirir. #include <stdio.h> #include <conio.h> void main() { char bolum[10]="bilgisayar"; printf("%s",bolum); // puts(bolum); getch (); } 9 String Fonksiyonları
  • 10. • gets(char str[]): Girdi olarak string almak için kullanılır, stringin sonuna ‘0’, null karakterini otomatik olarak ekler. #include <stdio.h> #include <conio.h> void main() { char bolum[10]; scanf("%s",bolum); // gets(bolum); getch (); } 10 String Fonksiyonları
  • 11. • string.h kütüphanesinde yer alanlar: • strlen(char str[]): Bir string (dizge) içindeki karakter sayısını bulmak için kullanılır. int adet=0; while(str[adet]!=‘0’) adet++; ya da adet=strlen(str); 11 String Fonksiyonları
  • 12. • strcpy(char str1[],char str2[]): str2 stringini str1 stringine kopyalama işlemini yapar. char ad[10]; strcpy(ad,"elanur"); • strncpy(char str1[],char str2[],int n): str2 stringindeki ilk n adet karakteri str1 stringine kopyalama işlemini yapar. 12 String Fonksiyonları
  • 13. • strcat(char str1[],char str2[]): str1 stringinin sonuna str2 stringinin eklenmesini sağlar. char str1[10]= “sınıf”; char str2[10]= “C112”; strcat(str1, str2); str1’ in yeni hali “sınıf C112” • strncat(char str1[],char str2[],int n): str1 stringinin sonuna str2 stringinin ilk n karakterinin eklenmesini sağlar. 13 String Fonksiyonları
  • 14. • strcmp(char str1[],char str2[]): str1 ve str2 stringlerini karşılaştırır: Eşit ise 0, str1 stringi sözlükte daha önce geliyorsa -1, str2 stringi daha önce geliyorsa 1 değerini döndürür. – strcmp(“Ankara”, “Ankara”)  0 – strcmp(“Ankara”, “Antalya”)  -1 – strcmp(“Antalya”, “Ankara”)  1 • strncmp(char str1[],char str2[],int n): str1 ve str2 stringlerinin ilk n karakterlerinin karşılaştırılmasını sağlar. 14 String Fonksiyonları
  • 15. • strrev(char str1[]): str1 stringini ters çevirir. • strstr(char str1[],char str2[]): str1 stringi içinde str2 stringini arar, ilk karşılaştığı yeri verir. 15 String Fonksiyonları #include <stdio.h> #include <conio.h> #include <string.h> void main() { char girdi[20]; puts("Bir string girin: "); gets(girdi); printf("%sn",strstr(girdi,"al")); getch (); }
  • 16. • strchr(char str1[],char x): str1 stringi içinde x karakterini arar, ilk karşılaştığı yeri verir. 16 String Fonksiyonları #include <stdio.h> #include <conio.h> #include <string.h> void main() { char girdi[20]; puts("Bir string girin: "); gets(girdi); printf("%sn",strchr(girdi,'a')); getch (); }
  • 17. • strlwr(char str1 []): str1 stringindeki büyük harfleri küçük harflere çevirir. • strupr(char str1 []): str1 stringindeki küçük harfleri büyük harflere çevirir. 17 String Fonksiyonları #include <stdio.h> #include <conio.h> #include <string.h> void main() { char ad[]="NeSiBe YaLCiN"; strupr(ad); printf("%sn",ad); strlwr(ad); printf("%s",ad); getch (); }
  • 18. • ctype.h kütüphanesinde yer alanlar: • isalnum(char x): Girilen x karakterin alfabetik ya da nümerik olup olmadığını sorgular. 18 String Fonksiyonları #include <stdio.h> #include <conio.h> #include <ctype.h> void main() { char x; puts("Bir karakter girin: "); scanf("%c",&x); if(isalnum(x)) printf("Alfabetik/Numerik"); else printf("Alfabetik/Numerik degil"); getch (); }
  • 19. • ctype.h kütüphanesinde yer alanlar: • isalpha(char x): x bir harf ise sıfırdan farklı, diğer durumlarda sıfır değerini döndürür. • isdigit(char x): x bir sayı ise sıfırdan farklı, diğer durumlarda sıfır değerini döndürür. • isspace(char x): x boşluk, yeni satır veya tab karakteri gibi bir karakterse sıfırdan farklı, diğer durumlarda sıfır değerini döndürür. 19 String Fonksiyonları
  • 20. • isupper(char x): x büyük bir harf ise sıfırdan farklı, diğer durumlarda sıfır değerini döndürür. • islower(char x): x küçük bir harf ise sıfırdan farklı, diğer durumlarda sıfır değerini döndürür. • sizeof(…. a): Donanım sisteminin a değişkenine ya da veri türüne ayırdığı bellek büyüklüğünü verir. 20 String Fonksiyonları
  • 21. • toupper(char x): x’ in değerinin büyük harf karşılığını verir. • tolower(char x): x’ in değerinin küçük harf karşılığını verir. 21 String Fonksiyonları #include <stdio.h> #include <conio.h> #include <ctype.h> void main() { char x; puts("Bir karakter girin: "); scanf("%c",&x); printf("%c",toupper(x)); printf("%c",tolower(x)); getch (); }
  • 22. 22 Uygulama Örnekleri // #include <string.h> #include <stdio.h> #include <conio.h> void main() { char str[20]="Muhendislik"; //for(int i=0;i<strlen(str);i++) for(int i=0;str[i]!='0';i++){ for(int j=0;j<i+1;j++) printf("%c",str[j]); printf("n"); } getch(); }
  • 23. 23 Uygulama Örnekleri #include <stdio.h> #include <conio.h> void main() { char girdi[20]; int i=0,sayac=0; puts("Bir string girin: "); gets(girdi); while(girdi[i] != '0'){ if( girdi[i] == 'a') sayac++; i++; } printf("'a' karakteri sayisi = %dn",sayac); printf("Toplam karakteri sayisi = %dn",i); printf("Ayrilan bellek buyuklugu %d byte",sizeof(girdi)); getch (); }
  • 24. 24 Uygulama Örnekleri #include <stdio.h> #include <conio.h> #include <string.h> void main() { char girdi[20]; int sayac=0; puts("Bir string girin: "); do{ gets(girdi); sayac++; }while( strcmp(girdi, "Ankara*06")!=0); printf("%d seferde bildinizn",sayac); getch (); }
  • 25. • Kullanıcı tarafından girilen bir karakter dizisi içindeki boşluk karakterini çıkaran programı C dilinde yazınız. • strstr fonksiyonu ile aynı görevi yapan void str_arama(char a[],char b[]) isimli kendi fonksiyonunu yazınız. • Kullanıcı tarafından girilen bir stringin Palindrom olup olmadığını bulan fonksiyonu yazınız. 2141412, ata, kazak, Ey Edip Adanada pide ye … 25 Uygulama Örnekleri