#include <iostream>
#include <ctype.h>
using namespace std;
typedef char Txt80[80];
int main()
{
char *PText;
Txt80 Txt = "Ur2GReAt";
int N = 6;
PText = Txt;
while (N >=3)
{
Txt[N] = (isupper(Txt[N] ? tolower(Txt[N]):toupper(Txt[N])));
cout << PText <<endl;
N--;
PText++;
}
}
Output is :
Ur2GRe
r2GR
2G
根据循环中使用的三元运算符,我很困惑,如果第6个值是小写字母,它应该将其转换为大写。这里'e'是小写的,但输出仍然是小写的,它只是在循环的第一次运行中打印前6个字符。然后在第二轮中N减少并从2打印。请解释
答案 0 :(得分:1)
看起来像这一行:
import scrapy
import json
class RentObject(scrapy.Item):
address = scrapy.Field()
purpose = scrapy.Field()
# Add more fields as needed
class ScrapeSpider(scrapy.Spider):
name = "rent_hk"
allowed_domains = ['591.com.hk']
start_urls = ['http://rent.591.com.hk/?hl=en-us#list' ]
page_number = 0
page_num_max = 5 # for test purposes grab only up to 5 pages
def parse(self, response):
if 'page_number' in response.meta:
result_dict = json.loads(response.body) # get data as dict
for object in result_dict['items']:
ro = RentObject()
ro['address'] = object['address']
ro['purpose'] = object['purpose']
yield ro
# Make request for (next page) JSON data
self.page_number += 1
payload = {
'm': 'home',
'c': 'search',
'a': 'rslist',
'type': '1',
'p': str(self.page_number),
'searchtype': '1'
}
if self.page_number < self.page_num_max:
request = scrapy.FormRequest(url='http://rent.591.com.hk/',
method='GET',
formdata=payload,
headers={'Referer': 'http://rent.591.com.hk/?hl=en-us',
'X-Requested-With': 'XMLHttpRequest'},
callback=self.parse)
request.meta['page_number'] = self.page_number
yield request
将Txt[N] = (isupper(Txt[N] ? tolower(Txt[N]):toupper(Txt[N])));
设置为零,从而有效地截断字符串。但是,支持的配置看起来很可疑 - 我想知道你是否意味着:
Txt[N]