我需要一个程序来计算.txt或.c文件的行,并返回以下内容:
文件:
简单注释:N行
多行注释:N行
总行数:N行
我有这个:
if (pFile != NULL)
{
do {
c = fgetc(pFile);
if (c == '\n') n++;
} while (c != EOF);
Run Code Online (Sandbox Code Playgroud)
我不知道如何实现其余部分.
我也尝试使用strstr()函数,但也没有得到它.
我打算在这里问这个问题.但是在我做之前我就解决了.我希望能够以更有序的方式打印这个Python 2.7列表.
not_shuffled_deck = ["%i of %s" % (i, s) for i in range(2,10) for s in ('spades', 'diamonds', 'clubs', 'hearts')]
for i in not_shuffled_deck:
print i + "|",
Run Code Online (Sandbox Code Playgroud)
这就是它最初的结果.
嗯,它实际上比它在这里显示的更糟糕.它取决于控制台大小,屏幕大小,是否有文本换行等.所以在我使用的控制台中,甚至在普通的文本编辑器中,它将以难以阅读的方式显示在多行上.
2 of spades| 2 of diamonds| 2 of clubs| 2 of hearts| 3 of spades| 3 of diamonds| 3 of clubs| 3 of hearts| 4 of spades| 4 of diamonds| 4 of clubs| 4 of hearts| 5 of spades| 5 of diamonds| 5 of clubs| 5 of hearts| 6 …
Run Code Online (Sandbox Code Playgroud) 有没有一种简单的方法可以在分割后打印最后一个字符串?
输入文件:
Name:DOB:Age
Name:Name2:DOB:Age
Run Code Online (Sandbox Code Playgroud)
我想要名字和年龄...
所以...
string = line.split(':')
print(string[0] + string[xxxx])
Run Code Online (Sandbox Code Playgroud)
有没有什么东西让 xxxx 总是打印最后一个字符串?
谢谢
我的 HTML 代码如下所示:
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-6">
<section class="widget index">
<header>
<h4>
<i class="fa fa-bars"></i> Status word <small> </small>
</h4>
</header>
<div class="body">
- Output A: <div class="dash_data_A"></div>
- Output B: <div class="dash_data_B"></div>
- Output C: <div class="dash_data_C"></div>
Run Code Online (Sandbox Code Playgroud)
网站上的显示如下:
- Output A:
false
- Output B:
true
- Output C:
false
Run Code Online (Sandbox Code Playgroud)
第一个愿望:输出值应该在同一行(避免换行),如下所示:
- Output A: false
- Output B: true
- Output C: false
Run Code Online (Sandbox Code Playgroud)
第二个愿望:输出值应该改变false(红色)和 true(绿色)的字体颜色。
我必须在 css 文件中实现它吗?还是在js里?或者两者兼而有之?你有什么建议吗?
我有两个有序的x(xcor
)和y(ycor
)值数组.加入第一个和最后一个点给出一条线.我想计算这条线上所有点的垂直距离.这类似于最小平方距离.有没有直接的方法在matlab中执行此操作?还请注意,距离的符号应代表该线的点的侧面.
xy =
-121.9067 -53.5483
-122.0750 -53.5475
-122.4750 -53.5243
-123.0975 -53.4835
-123.9050 -53.4168
-124.8050 -53.3235
-125.7025 -53.2467
-126.5675 -53.1800
-127.3825 -53.1215
-128.1500 -53.0798
-128.8825 -53.0468
-129.6000 -53.0452
-130.3150 -53.1133
-131.0400 -53.2532
-131.7850 -53.4513
-132.5525 -53.6877
-133.3425 -53.9345
-134.1600 -54.1758
-135.0075 -54.4115
-135.8675 -54.6480
-136.7375 -54.9040
-137.5075 -55.2635
-138.1875 -55.7435
-138.7775 -56.3333
-139.2850 -57.0665
-139.8450 -57.9285
-140.4550 -58.9492
-141.1575 -60.0988
-141.9825 -61.3415
-142.9275 -62.6172
-144.0050 -63.8517
-145.2125 -65.0523
-146.5450 -66.1715
-147.9950 -67.1727
-149.5575 -68.0570
-151.2225 -68.8152
-152.9925 …
Run Code Online (Sandbox Code Playgroud) 我正在学习C++。这是我的问题。
我创建了一个可以读取像它们一样的 Prop 文件的函数(您可以使用函数设置文件开始和结束标签,使用将返回字符串(包含结果)的函数搜索指定标签。
这是main.cpp
#include <iostream>
#include "m_PFile_r.h"
using namespace std;
int main(int argc, const char * argv[])
{
m_PFile_r k;
k.open("prop.arg");
k.imNotaFag(true);
k.setOpenArg("$FILE_BEGIN$");
k.setCloseArg("$FILE_END$");
string lS;
lS=k.getArg("launchSentence");
cout << lS << endl;
string menu;
menu=k.getArg("progMenu");
cout << menu;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么它不打印 \n 作为换行符?
谢谢 :)
# include <stdio.h>
double simpleInterest (double Princ, double Rate, int Time)
{
double value;
value = Princ*Rate*Time;
retrun value;
}
int main (int argc, char * argv [])
{
printf ("value is £%5.2\n", simpleInterest(100,0.05,1);
printf ("value is £%5.2\n", simpleInterest(1,0.01,10);
}
Run Code Online (Sandbox Code Playgroud)
我得到一个错误说预期';' 之前')'令牌,但我不明白我已经放了一个; 在每一行之后.我应该把别人放在其他地方吗?