我写了一个简单的C++程序来反转一个字符串.我在字符数组中存储一个字符串.要反转字符串,我使用相同的字符数组和临时变量来交换数组的字符.
#include<iostream>
#include<string>
using namespace std;
void reverseChar(char* str);
char str[50],rstr[50];
int i,n;
int main()
{
cout<<"Please Enter the String: ";
cin.getline(str,50);
reverseChar(str);
cout<<str;
return 0;
}
void reverseChar(char* str)
{
for(i=0;i<sizeof(str)/2;i++)
{
char temp=str[i];
str[i]=str[sizeof(str)-i-1];
str[sizeof(str)-i-1]=temp;
}
}
Run Code Online (Sandbox Code Playgroud)
现在这个方法不起作用,我在程序执行后获得NULL String作为结果.
所以我想知道为什么我不能将字符数组等同,为什么这个程序不起作用.我可以使用什么解决方案或技巧来使相同的程序工作?
我正在使用Spark对用户日志文件进行探索性数据分析.我正在做的一项分析是每个主机每天的平均请求.因此,为了计算平均值,我需要将DataFrame的总请求列除以DataFrame的数字唯一Request列.
total_req_per_day_df = logs_df.select('host',dayofmonth('time').alias('day')).groupby('day').count()
avg_daily_req_per_host_df = total_req_per_day_df.select("day",(total_req_per_day_df["count"] / daily_hosts_df["count"]).alias("count"))
Run Code Online (Sandbox Code Playgroud)
这就是我用PySpark编写的用来确定平均值的内容.这是我得到的错误日志
AnalysisException: u'resolved attribute(s) count#1993L missing from day#3628,count#3629L in operator !Project [day#3628,(cast(count#3629L as double) / cast(count#1993L as double)) AS count#3630];
Run Code Online (Sandbox Code Playgroud)
注意:daily_hosts_df和logs_df缓存在内存中.如何划分两个数据帧的计数列?