實現一個函式,把一個字串中的字元從小寫轉為大寫。
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void upper(char* s, char* us)
{
while(*s != '\0')
{
if(*s >= 'a' && *s <= 'z')
{
*us = *s - 32;
}
else
{
*us = *s;
}
s++;
us++;
}
*us = '\0';//注意不要漏了這一句
}
int main()
{
char A[20],B[20];
printf("Please input a string:\n");
scanf_s("%s", A, 20);
upper(A,B);
printf("%s", B);
printf("%c", A[19]);//A[19]存的是'\0'
}
相關推薦
實現一個函式,把一個字串中的字元從小寫轉為大寫。
#include <stdio.h> #include <stdlib.h> #include <conio.h> void upper(char* s, char* us) { while(*s != '\0')
實現一個函式,把一個字串轉換成整數
作者:翁鬆秀 劍指offer之“把一個字串轉換成整數” 很多人看到這麼簡單的面試題目,都是大筆一揮,立馬寫下洋洋灑灑函式: int StringToInt(char* string){ int num = 0; while(*str
【練習題】編寫一個函式,把一個char組成的字串迴圈右移n位
例如:原來是”abcdefghi”,如果n = 2,移位後應該是”hiabcdefg”。 思路:當讀到這個題目的時候,沒有編寫過類似程式的人可能會想,程式的實現就是依照字元的迴圈右移這樣實現的,但仔細想會發現這樣很難實現,不妨換一種思路,我們先把需要移到前面的字元取出來放進
【c語言】字串替換空格:請實現一個函式,把字串中的每個空格替換成“%20”
// 字串替換空格:請實現一個函式,把字串中的每個空格替換成“%20”。 // 例如輸入“we are happy.”,則輸出“we%20are%20happy.” #include <stdio.h> #include <assert.h>
【我的演算法日記】請實現一個函式,把字串中的每個空格替換成“%20”。例如輸入“We are happy.”,則輸出“We%20are%20happy.”。
請實現一個函式,把字串中的每個空格替換成“%20”。例如輸入“We are happy.”,則輸出“We%20are%20happy.”。在劍指offer中有這樣一道題目,我已經既不清楚了,我記得該題好像不準使用輔助空間,需要在遠字串上進行操作,如果在java中,直接用re
請實現一個函式,把字串中的每個空格替換成“%20”,例如輸入 “We are Happly。” 則輸出“we%20are%20happy。”
請實現一個函式,把字串中的每個空格替換成“%20”,例如輸入 “We are Happly。” 則輸出“we%20are%20happy。” void ReplaceBlank(char String[],int length) { //originalLength
字串替換空格:請實現一個函式,把字元陣列中的每個空格替換成“%20”
例如輸入“we are happy”,則輸出“we%20are%20happy” 想要實現這個目的,先觀察下面的函式實現原理圖。 先通過遍歷字元陣列,找出其中的空格數,計算出應該移動到的位置,接著就
【劍指offer】請實現一個函式,將一個字串中的每個空格替換
劍指offer 題目如下 請實現一個函式,將一個字串中的每個空格替換成"%20"。 例如,當字串為We Are Happy, 則經過替換後的字串為 We%20Are%20Happy。 具體的程式碼實現如下 1.遍歷實現 public class Solution {
請實現一個函式,將一個字串中的每個空格替換成指定符號。
題目描述 請實現一個函式,將一個字串中的每個空格替換成“%20”。例如,當字串為We Are Happy.則經過替換之後的字串為We%20Are%20Happy。 /* 思路:從前向後記錄‘ ’數目,從後向前替換‘ ’。 重點:從後向前替換的時候的技巧 例如:“we are lucky”
java 劍指offer 第二題:請實現一個函式,將一個字串中的空格替換成“%20”。例如,當字串為We Are Happy.則經過替換之後的字串為We%20Are%20Happy。
** public class Solution { public String replaceSpace(StringBuffer str) { 首先程式給出的引數是StringBuffer類,那麼我首先考慮的是就呼叫StringBuffer類的相關方法完成操作。
請實現一個函式,將一個字串中的空格替換成“%20”。例如,當字串為We Are Happy.則經過替換之後的字串為We%20Are%20Happy。
string replaceSpace(string str) { int num_black=0; int len_str = str.length(); char array_str[20
請實現一個函式,將一個字串中的每個空格替換成“%20”。例如,當字串為We Are Happy.則經過替換之後的字串為We%20Are%20Happy。
public class Solution { public String replaceSpace(StringBuffer s
有一字串,包含n個字元。寫一函式,將此字串中從第m個字元開始的全部字元複製成為另一個字串。
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanne
ACMNO.40 C語言-子串 有一字串,包含n個字元。寫一函式,將此字串中從第m個字元開始的全部字元複製成為另一個字串
題目描述 有一字串,包含n個字元。 寫一函式,將此字串中從第m個字元開始的全部字元複製成為另一個字串。 輸入 數字n 一行字串 數字m 輸出 從m開始的子串 樣例輸入 6 abcdef 3 樣例輸出 cdef 來源/分類 C語言
實現一個函式, 可以左旋字串中的k個字元
** 實現一個函式,可以左旋字串中的k個字元。 ABCD左旋一個字元得到BCDA ABCD左旋兩個字元得到CDAB ** #include <stdio.h>
編寫一個程式,實現從命令列引數輸入一字串,統計該字串中字元輸入字元的出現的次數。
package pro1214test; import java.util.Scanner; public class eCiShu { public static void main(String[] args) { Scanner s = new Scanner(System.
【阿里前端測評題】實現 mergePromise 函式,把傳進去的陣列順序先後執行,並且把返回的資料先後放到陣列(data)中
const timeout = ms => new Promise((resolve) => { setTimeout(() => { resolve();
8.7 有一字串,包含n個字元。寫一個函式,將此字串從第 m個字元開始的全部字元複製成為另一個字串。
8.7 有一字串,包含n個字元。寫一個函式,將此字串從第 m個字元開始的全部字元複製成為另一個字串。個人程式碼如下:#include<stdio.h> #include<string.
6-6 求單鏈表結點的階乘和(15 分) 本題要求實現一個函式,求單鏈表L結點的階乘和。這裡預設所有結點的值非負,且題目保證結果在int範圍內。
int FactorialSum( List L ){ int max=0,sum=0; List p,head; head=L; p=head; while(p!=NULL) { if(max<p->Data) max=p->Dat
.編寫一個函式,將一個數字字串轉換成該字串對應的數字
/* 編寫一個函式,將一個數字字串轉換成該字串對應的數字(包括正整數、負整數) 例如:“12“ 返回12 “-123“ 返回-123 函式原型:int my_atof(char *str){