C++ char* uppercase / lowercase
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
const char *txt1 = "tosun can";
//--------------------------------------------------
char* tmp1 = strdup(txt1);//const olan objeyi değiştirilebilir olarak kopyalıyorUZ
for (size_t i = 0; i < strlen(tmp1); i++)
{
tmp1 [ i ] = toupper(tmp1 [ i ] );
}
//--------------------------------------------------
//alternatif yöntem / alternate
int lenx = strlen(txt1);
char* tmp2 = (char*)malloc(lenx + 1);
for (size_t i = 0; i < lenx; i++)
{
tmp2 [ i ] = toupper(txt1 [ i ]);
}
// normal uzunluga ek olarak atanan (+1) en son karakter olmazsa olmaz zira
// verinin bittiğini ifade etmemiz gerekiyor bellekte. götü başı belli olmalı!
tmp2[lenx] = '\0'; //END OF BLOCK
//--------------------------------------------------
cout << tmp1 << endl; //TOSUN CAN
cout << tmp2 << endl; //TOSUN CAN
return 0;
}
ref: Visual C++ / C++ char* uppercase / lowercase
------------- http://www.kasatakip.com - Kasa Takip | http://www.caritakip.com - Cari Takip | http://www.evraktakip.com - Evrak Takip | http://www.etasqlmobil.com - ETA SQL Mobil
|