问题描述
在此代码中,我尝试打印文件中的其余行,但我使用ID卡号选择的行除外。但是数据向我显示了结果const { ApolloServer,gql,mergeSchemas,introspectSchema,makeRemoteExecutableSchema } = require('apollo-server')
const { HttpLink } = require('apollo-link-http')
const fetch = require('node-fetch')
const { WebSocketLink } = require('apollo-link-ws')
const { split } = require('apollo-link')
const { getMainDeFinition } = require('apollo-utilities')
const { SubscriptionClient } = require('subscriptions-transport-ws')
const ws = require('ws')
const resolvers = {}
async function getRemoteSchema({ uri,subscriptionsUri }) {
const httpLink = new HttpLink({ uri,fetch })
const client = new SubscriptionClient(subscriptionsUri,{ reconnect: true },ws)
const wsLink = new WebSocketLink(client)
const link = split(
operation => {
const deFinition = getMainDeFinition(operation.query)
console.log(deFinition)
return (
deFinition.kind === 'OperationDeFinition' &&
deFinition.operation === 'subscription'
)
},wsLink,// <-- Use this if above function returns true
httpLink // <-- Use this if above function returns false
)
const schema = await introspectSchema(link)
const executableSchema = makeRemoteExecutableSchema({ schema,link })
return executableSchema
}
async function run() {
//
const remoteSchema1 = await getRemoteSchema({ uri: 'http://127.0.0.1:8000',subscriptionsUri: 'ws://localhost:8005/subscriptions'
})
const remoteSchema3 = await getRemoteSchema({
uri: 'http://localhost:8005/graphql',subscriptionsUri: 'ws://localhost:8005/subscriptions'
})
const resolvers = {}
const schema = mergeSchemas({
schemas: [
remoteSchema1,remoteSchema3,],})
const server = new ApolloServer({ schema })
server.listen().then(({ url,subscriptionsUrl }) => {
console.log(`? Server ready at ${url}`);
console.log(`? Subscriptions ready at ${subscriptionsUrl}`);
})
}
run().catch(console.log)
like
我希望在打印完所有数据后最后重复data1....
Above are the remaining lines
data2....
Above are the remaining lines
data3....
Above are the remaining lines
。
Above are the remaining lines
解决方法
解决方案是将要打印的字符串放在while
之外。
为完成操作,您可以使用flag
仅在实际上还有剩余行的情况下打印"Above are the remaining lines"
:
int flag = 0; //flag declaration
while (fgets(string,sizeof string,fp1)) {
//lines = strtok(string,"\n"); //this is doing nothing meaningful
result = strstr(string,toFind); //use string instead
if (!result)
{
printf("%s\n",string);
if (!flag)
flag = 1;
}
}
if (flag)
printf("Above are the remaining lines\n");
示例:
文件内容:
1234....
4567....
8910....
输入:
4567
输出:
1234....
8910....
Above are the remaining lines