【C語言】自己編寫程式實現strrchr函式,即在給定字串中找特定的字元並返回最後出現的位置
//自己編寫程式實現strrchr函式,即在給定字串中找特定的字元並返回最後出現的位置 #include <stdio.h> #include <string.h> char * my_strrchr(char const *str,int ch) { int count=0; while(*str!='\0') { count++; str++; } str--; while(count) { if(*str!=ch) { str--; count--; } else return str; } printf("未找到該字元。\n"); return 0; } int main() { char *p="abcdefabcdef"; char a; printf("請輸入您要查詢的字元:"); scanf("%c",&a); printf("%s\n",my_strrchr(p,a)); return 0; }
相關推薦
【C語言】自己編寫程式實現strrchr函式,即在給定字串中找特定的字元並返回最後出現的位置
//自己編寫程式實現strrchr函式,即在給定字串中找特定的字元並返回最後出現的位置 #include <stdio.h> #include <string.h> char
【C語言】自己編寫程式實現strchr函式。即在給定字串中找特定的字元並返回該處指標。
<pre name="code" class="cpp">//自己編寫程式實現strchr函式。即在給定字串中找特定的字元並返回該處指標。 #include <stdio.h>
【c語言】利用指標模式實現字串函式(strlen、strcat、strstr、strcpy、strcmp、memcpy、memove)
模擬實現strlen int my_strlen(const char *p) { assert(p != NULL); char *s = p; while (*p) { p++; } r
【C語言】單鏈表的實現
單鏈表 單鏈表是一種鏈式存取的資料結構,用一組地址任意的儲存單元存放線性表中的資料元素。 單鏈表結構如下: typedef int DataType; typedef struct Node { struct Node* next; /
【c語言】設圓半徑r = 1.5,圓柱高h = 3,求圓周長,圓面積,圓球表面積,圓球體積,圓柱體積
要求scanf輸入資料,並有相應文字說明 #include<stdio.h> int main() { float r,h,pi=3.141592 ; printf("請輸入圓半徑r和圓柱高h:"); scanf("%f%f",&r,&h); printf(
【C語言】ASCII碼的數字轉字母,字母轉數字的方法
#include <stdio.h> int main(){ //輸入字母,再輸出字母的方法 printf("輸入字母,再輸出字母的方法\n"); char c1,c2; scanf("%c,%c",&
【c語言】給出三角形的三邊長,求三角形面積
設三角形三邊長為a、b、c,並滿足約束條件三邊之和大於第三邊,面積為Area 則: 其中 C語言程式碼: #include <stdio.h> #include <math.h> int main() { double a
【C語言】(windows.h)ShellExecute函式
【SHELL EXECUTE引數說明】 ShellExecute是Windows系統裡面進行操作的一個函式 ( 例如 ) 開啟一個網站: ShellExecute(0, "open", "https://user.qzone.qq.com/82810
【劍指offer】請實現一個函式,將一個字串中的每個空格替換
劍指offer 題目如下 請實現一個函式,將一個字串中的每個空格替換成"%20"。 例如,當字串為We Are Happy, 則經過替換後的字串為 We%20Are%20Happy。 具體的程式碼實現如下 1.遍歷實現 public class Solution {
編寫一個函式實現atoi()函式,即把字串數字轉變為數字
#include<iostream> #include<ctype.h> #include <math.h> using namespace std; int l
請實現一個函式,將一個字串中的每個空格替換成指定符號。
題目描述 請實現一個函式,將一個字串中的每個空格替換成“%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類的相關方法完成操作。
實現一個函式,把一個字串中的字元從小寫轉為大寫。
#include <stdio.h> #include <stdlib.h> #include <conio.h> void upper(char* s, char* us) { while(*s != '\0')
請實現一個函式,將一個字串中的空格替換成“%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
【c語言】寫程式編寫2-10000以內的完全數
/* 需求:寫程式編寫2-10000以內的完全數 完全數 求一個數的因子(除了這個數本身)之和等於該數本身 例如: 6的因子是1 2 3 因子和1+2+3=6 因此6是完全數 程式理解: 第一個for迴圈是遍歷2-10000之間的數 第二個for迴圈是遍歷符合條件的數字 **/ #inclu
【c語言】編寫程式打印出以下形式的楊輝三角形
楊輝三角形 可以將楊輝三角形的值放在一個方形矩陣的下半三角中,如需列印7行楊輝三角形,應該定義等於或大於7x7的方形矩陣,只是矩陣的上半部分和其餘部分並不使用。 楊輝三角形具有以下特點: (1)第一列和對角線上的元素都為1; (2)除第一列和對角線上的元素之外,其他的元素的值均
【C語言】【unix c】編寫程式碼測試自己電腦的位元組序
編寫程式碼測試自己電腦的位元組序 #include <stdio.h> int main(void) { char arr[5] = {'a','b','c','s','w'};
【C語言】編寫一個程式顯示當前時間。
#include<sys/time.h> #include<time.h> #include<stdio.h> int main() {struct tm *ptm;time_t ts;char tim[50];ts = time(NUL
【C語言】編寫函式實現庫函式atoi,把字串轉換成整形
//編寫函式實現庫函式atoi,把字串轉換成整形 #include <stdio.h> #include <string.h> int my_atoi(const char *