#include <stdio.h>#define maxsize 100typedef struct cstr{ char data[maxsize]; int len;}sqstring;sqstring *initsring(char a[]){ sqstring *l; l=(sqstring*)malloc(sizeof(sqstring)); int i=0; while(a[i]) { l->data[i]=a[i]; i++; } l->len=i; return l;}void printstring(sqstring *l){ int i=0; for(i=0;i<l->len;i++) { printf("%c",l->data[i]); } printf("\n");}sqstring *concat(sqstring *s,sqstring *t){ sqstring *l = initsring(""); int i=0; for(i=0;i<s->len;i++) { l->data[i]=s->data[i]; }


for(int j=0;j<t->len;j++) { l->data[i+j]=t->data[j]; } l->len=i+j; return l;}int main(){ char a[]="Hello "; char b[]="World!"; sqstring *s = initsring(a); sqstring *t = initsring(b); printstring(s); printstring(t); sqstring *u = concat(s,t); printstring(u); return 0;} [2024-11-15 17:13:22 | AI写代码神器 | 182点数解答]
相关提问
- #include <stdio.h>#define maxsize 100typedef struct cstr{ char data[maxsize]; int len;}sqstring;sqstring *initsring(char a[]){ sqstring *l; l=(sqstring*)malloc(sizeof(sqstring)); int i=0; while(a[i]) { l->data[i]=a[i]; i++; } l->len=i; return l;}void printstring(sqstring *l){ int i=0; for(i=0;i<l->len;i++) { printf("%c",l->data[i]); } printf("\n");}sqstring *concat(sqstring *s,sqstring *t){ sqstring *l = initsring(""); int i=0; for(i=0;i<s->len;i++) { l->data[i]=s->data[i]; }(182点数解答 | 2024-11-15 17:13:22)172
- #include <stdio.h> #include <stdlib.h> #define maxsize 100 typedef struct cstr { char data[maxsize]; int len; } sqstring; // 初始化字符串 sqstring *initstring(char a[]) { sqstring *l; l = (sqstring *)malloc(sizeof(sqstring)); int i = 0; while (a[i]) { l->data[i] = a[i]; i++; } l->data[i] = '\0'; // 添加空字符 l->len = i; return l; } // 打印字符串 void printstring(sqstring *l) { int i = 0; for (i = 0; i < l->len; i++) { printf("%c", l->da(308点数解答 | 2024-11-15 17:12:32)116
- #include<iostream> #include<complex.h> #include <complex> #include <math.h> using namespace std; #define pi 3.14159265358979323846 int main() { file* stream; stream = fopen("4000-red.raw","rb"); unsigned char* image = (unsigned char*)malloc(4000 * 4000 * sizeof(unsigned char)); fread(image,4000*4000,sizeof(unsigned char),stream); unsigned char* image2 = (unsigned char*)malloc(4000 * 4000 * sizeof(unsigned char)); unsigned char* image3 = (unsigned char*)malloc(4000 * 4000 * sizeof(unsigned(413点数解答 | 2024-11-02 18:16:35)193
- #include<stdio.h> #include<stdlib.h> #include<time.h> int producerand(int remainder); void initprocess(); void chosedisplace(); struct linknode* fifo(struct linknode* head, int randcount); void optimal(struct linknode* head, int randprocess); struct linknode* lru(struct linknode* head, int randprocess); struct linknode* initlink(); void choicestey(); int allotment(struct linknode* head); int checkfifooptimal(struct linknode* head, int checkpage); void recover(struct linknode* head, int randproc(60点数解答 | 2024-12-13 20:02:21)189
- #include<stdio.h> #include<stdlib.h> #include<time.h> int producerand(int remainder); void initprocess(); void chosedisplace(); struct linknode* fifo(struct linknode* head, int randcount); void optimal(struct linknode* head, int randprocess); struct linknode* lru(struct linknode* head, int randprocess); struct linknode* initlink(); void choicestey(); int allotment(struct linknode* head); int checkfifooptimal(struct linknode* head, int checkpage); void recover(struct linknode* head, int randproc(858点数解答 | 2024-12-13 20:03:47)169
- #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #define maxsize 100 typedef char elemtype; typedef struct node { elemtype data; struct node* lchild; struct node* rchild; } btnode; typedef struct { btnode* data[maxsize]; int top; } stacktype; void initstack(stacktype* st) { st->top = -1; } bool stackempty(stacktype* st) { return st->top == -1; } bool push(stacktype* st, btnode* e) { if (st->top < maxsize - 1) { st->data[++st->top] = e;(95点数解答 | 2024-12-10 13:17:25)126
- #include<stdio.h> #include<malloc.h>//动态存储分配函数头文件 #include<math.h>//包含数学函数的文件 #include<string.h>//一个和字符串处理相关的头文件 #include<process.h>//包含用于和宏指令的作用声明 #define error 0 //宏定义 #define ok 1 #define over -2 #define listinitsize 20 #define listincrement 5 #define namelen 8 #define majorlen 20 #define init_n 3 typedef int status; //自定义类型语句 status i 等价于 int i typedef char statusc; typedef struct{ statusc number[10]; //学号 statusc name[namelen+1]; //姓名 statusc gender; //性别 statusc telephone[12]; //电话 st(1142点数解答 | 2024-11-07 19:08:54)153
- #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <time.h> #include <conio.h> #include <unistd.h> #define mapheight 24 #define mapwidth 60 struct { int x; int y; } bean; struct { int x; int y; } eater; int key; int score1=0; void gotoxy(int x,int y); void drawmap(); void createbean(); void updatescore(); void keydown(); //0.光标 void gotoxy(int x,int y) { //控制输出时的光标位置 handle hout = getstdhandle(std_output_handle); coord pos; pos.x =x; pos.y =y; setconsolecursorpos(66点数解答 | 2024-11-15 22:33:26)187
- #include <iostream> #include <stdlib.h> #include <stdio.h> #include<string.h> using namespace std; #define null 0 #define maxsize 100 typedef char datatype; typedef struct node { datatype data[maxsize]; int length; }seqstring; void creat(seqstring *s)//建立字符串顺序表 { scanf("%s",s->data); s->length=strlen(s->data); } void print(seqstring str)//输出字符串 ,以'\0'结尾 { printf("list is:%s\n",str.data); } /*在字符串str中从第i个位置起取长度为len的子串(i从1开始),函数返回子串指针,若子串超出边界返回null。*/ seqstring* substring((146点数解答 | 2024-10-16 08:51:55)160
- #include <stdio.h> void sort(char *p); int main(void) { char str[21] ; gets(str); sort(str); puts(str); return 0; } void sort(char *p) { int i,len=strlen(*p),ln=len-2,j; char *q; strncpy(q,*(p+1),len-2); for(i=0;i<len-3;i++) { for(j=0;j<ln-1;j++) { if(*(q+j)<*(q+j+1)) { int t=*(q+j); *(q+j)=*(q+j+1); *(q+j+1)=t; } ln--; } } strncpy(*(p+1),q,len-2); }(664点数解答 | 2024-12-06 09:27:31)179
- #include <stdio.h> #include <stdlib.h> #include <string.h> #define max_tree_nodes 256 #define max_code_length 256 // 哈夫曼树节点结构体 typedef struct huffmannode { char character; int frequency; struct huffmannode *left, *right; } huffmannode; // 最小堆结构体 typedef struct minheap { int size; int capacity; huffmannode **array; } minheap; // 创建新的哈夫曼节点 huffmannode* createhuffmannode(char character, int frequency) { huffmannode* node = (huffmannode*)malloc(sizeof(huffmannode));(168点数解答 | 2024-11-10 17:18:39)150
- #include <stdio.h> #include <stdlib.h> #include <string.h> #define max_tree_nodes 256 #define max_code_length 256 // 哈夫曼树节点结构体 typedef struct huffmannode { char character; int frequency; struct huffmannode *left, *right; } huffmannode; // 最小堆结构体 typedef struct minheap { int size; int capacity; huffmannode **array; } minheap; // 创建新的哈夫曼节点 huffmannode* createhuffmannode(char character, int frequency) { huffmannode* node = (huffmannode*)malloc(sizeof(huffmannode));(1367点数解答 | 2024-11-10 17:20:01)167