解决cast from 'char*' to 'char**' increases required alignment of target type [-Werror=cast-align]

 cast from 'char*' to 'char**' increases required alignment of target type [-Werror=cast-align]

 

如#define NEXT(t)  ((char **)(t))[nextCol]

 

改由memcpy替换。

  NEXT (tuple) = tuple + tupleLen;-->


  char* pCharTemp = tuple + tupleLen;
  memcpy(tuple + nextCol, &pCharTemp, sizeof(char*));
  tuple += tupleLen;

Based on the given requirements, here's the implementation of the two occurrence functions (`occurrence1` and `occurrence2`) in C: ```c #include <stdio.h> #include <string.h> int occurrence1(char *sub, char *str) { if (*str == '\0') return 0; else if (strncmp(sub, str, strlen(sub)) == 0) return 1 + occurrence1(sub, str + strlen(sub)); else return occurrence1(sub, str + 1); } int occurrence2(char *sub, char *str) { int count = 0; int sub_len = strlen(sub); int str_len = strlen(str); for (int i = 0; i <= str_len - sub_len; i++) { if (strncmp(sub, str + i, sub_len) == 0) count++; } return count; } int main() { char str1[20], str2[80]; scanf("%s%s", str1, str2); printf("%d\n", occurrence1(str1, str2)); printf("%d\n", occurrence2(str1, str2)); return 0; } ``` In this program, the `occurrence1` function uses recursion to find the number of occurrences of `sub` in `str`. It checks if the current substring of `str` matches the `sub` string. If there is a match, it increases the count by 1 and recursively calls `occurrence1` on the remaining part of `str`. If there is no match, it recursively calls `occurrence1` on `str` excluding the first character. The `occurrence2` function is a non-recursive alternative that uses a loop to iterate over `str` and compare substrings of length `sub_len` with `sub`. It increases the count whenever a match is found. The main function reads two strings from input using `scanf` and then calls `occurrence1` and `occurrence2` functions respectively to find the occurrences of `str1` in `str2`, printing the results using `printf`. Please note that the program assumes the input strings (`str1` and `str2`) are null-terminated strings.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值