我试图将char指针类型传递为函数的返回类型,但没有获得任何输出。这是代码:
#include<stdio.h>
#include<string.h>
char * decrypt(char* pt)
{
char* result=malloc(20);
while(*pt)
{
*result=*pt+3;//incrementing by 3 alphbets and copying in reslult
pt++;
result++;
}
*result='\0';
return result;
}
int main()
{
char plaintext[20];
scanf("%s",plaintext);//getting input
char *ct= decrypt(plaintext); //passing to function
printf("\nCiphertext %s",ct);//printing reslut
}
答案 0 :(得分:2)
list_1 = ['house','table','house']
list_2 = ['desk','computer','table']
# instantiate a dict that will contain the number of appearances in each list, as a list
appearances = {}
# loop through the first list
for item in list_1:
# If the item hasn't appeared yet, it will set the item's name as the key and [1, 0] as the value
# appearances[item] is how we're going to set the key name in appearances
# appearances.get(item, 0)[0] makes it so that if item is not a key in appearances, it sets the initial value at index 0 to [0, 0].
# Otherwise, it sets it to +1 of it's current value
# We set appearances[item] to a list so that we can keep track of appearances in both lists
# For list_1's first item, appearances would then be equal to: appearances = {'house': [1, 0]}
appearances[item] = [appearances.get(item, [0, 0])[0] + 1, 0]
# Do the same for the second list, but use index of 1, instead of 0
for item in list_2:
# We use appearances.get() twice in case we haven't seen the item yet in either list
appearances[item] = [appearances.get(item, [0, 0])[0], appearances.get(item, [0, 0])[1] + 1]
# Print the result
print(appearances)
将在循环后指向result
。
只需添加临时指针以指向字符串的开头并返回即可。
\0